ATLAS Offline Software
Classes | Public Member Functions | Public Attributes | List of all members
xAODChargedTracksWeightFilter::Spline Struct Reference

#include <xAODChargedTracksWeightFilter.h>

Collaboration diagram for xAODChargedTracksWeightFilter::Spline:

Classes

struct  Point
 Linear spline representation of a function used to calculate weights. More...
 

Public Member Functions

StatusCode initialize (std::vector< double > &x, std::vector< double > &y)
 
double get_minimum (double min, double max) const
 get minimum over certain range (requires initialization to extrapolate) More...
 
double value (int nch) const
 get value for certain x More...
 

Public Attributes

std::vector< Pointpoints
 n-1 spline points filled at initialization More...
 

Detailed Description

Definition at line 28 of file xAODChargedTracksWeightFilter.h.

Member Function Documentation

◆ get_minimum()

double xAODChargedTracksWeightFilter::Spline::get_minimum ( double  min,
double  max 
) const

get minimum over certain range (requires initialization to extrapolate)

Definition at line 238 of file xAODChargedTracksWeightFilter.cxx.

238  {
239  // evaluate minimum of the spline over a defined range
240 
241  // spline must be initialized
242  if(points.empty()) return -1;
243 
244  const double dummy = -1;
245 
246  // if min, max are in between points, or extrapolation needed
247  auto minimum = std::min(value(min), value(max));
248 
249  // find boundary points and scan the allowed range
250  auto min_item = std::lower_bound(points.begin(), points.end(), Point(min, dummy, dummy), comp_x);
251  auto max_item = std::upper_bound(points.begin(), points.end(), Point(max, dummy, dummy), comp_x);
252 
253  if(min_item != max_item) {
254  const auto smallest = std::min_element(min_item, max_item, comp_y);
255  minimum = std::min(minimum, smallest-> y);
256  }
257 
258  return minimum;
259 }

◆ initialize()

StatusCode xAODChargedTracksWeightFilter::Spline::initialize ( std::vector< double > &  x,
std::vector< double > &  y 
)

Definition at line 261 of file xAODChargedTracksWeightFilter.cxx.

261  {
262 
263  if(x.size() < 2 || x.size() != y.size()) {
264  std::cout << "Spline not properly defined. SplineX, SplineY vectors are required to have at least 2 elements and same size.\n";
265  return StatusCode::FAILURE;
266  }
267 
268  // calculate slope terms
269  for(size_t i=0; i< x.size()-1; i++){
270 
271  const auto & x0 = x[i];
272  const auto & y0 = y[i];
273  const auto & x1 = x[i+1];
274  const auto & y1 = y[i+1];
275 
276  const auto dx = x1 - x0;
277  const auto dy = y1 - y0;
278 
279  if(dx <=0) {
280  std::cout << "Spline not properly defined. SplineX is required to be monotonically increasing.\n";
281  return StatusCode::FAILURE;
282  }
283 
284  points.push_back( Point(x[i], y[i], dy/dx));
285  }
286 
287  return StatusCode::SUCCESS;
288 }

◆ value()

double xAODChargedTracksWeightFilter::Spline::value ( int  nch) const

get value for certain x

Definition at line 217 of file xAODChargedTracksWeightFilter.cxx.

217  {
218 
219  const double dummy = -1;
220 
221  // find lowest weight in allowed range
222  auto lower = std::upper_bound(points.begin(), points.end(),
223  Point(nch, dummy, dummy), comp_x);
224 
225  if(lower != points.begin()) lower--;
226 
227  const auto & x = lower-> x;
228  const auto & y = lower-> y;;
229  const auto & slope = lower-> slope;;
230 
231  // weight using linear spline
232  const auto w_fc = (nch-x)*slope + y;
233 
234  if(w_fc<0) return 0; // extrapolation gives negative value
235  else return w_fc;
236 }

Member Data Documentation

◆ points

std::vector<Point> xAODChargedTracksWeightFilter::Spline::points

n-1 spline points filled at initialization

Definition at line 42 of file xAODChargedTracksWeightFilter.h.


The documentation for this struct was generated from the following files:
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
max
#define max(a, b)
Definition: cfImp.cxx:41
xAODChargedTracksWeightFilter::Spline::value
double value(int nch) const
get value for certain x
Definition: xAODChargedTracksWeightFilter.cxx:217
xAODChargedTracksWeightFilter::Spline::points
std::vector< Point > points
n-1 spline points filled at initialization
Definition: xAODChargedTracksWeightFilter.h:42
comp_y
bool comp_y(const Point &lhs, const Point &rhs)
Definition: xAODChargedTracksWeightFilter.cxx:213
x
#define x
makeTRTBarrelCans.y1
tuple y1
Definition: makeTRTBarrelCans.py:15
lumiFormat.i
int i
Definition: lumiFormat.py:92
python.xAODType.dummy
dummy
Definition: xAODType.py:4
min
#define min(a, b)
Definition: cfImp.cxx:40
ChargedTracksWeightFilter::Spline::Point
Linear spline representation of a function used to calculate weights.
Definition: ChargedTracksWeightFilter.h:28
Point
xAODChargedTracksWeightFilter::Spline::Point Point
Definition: xAODChargedTracksWeightFilter.cxx:11
makeTRTBarrelCans.dy
tuple dy
Definition: makeTRTBarrelCans.py:21
y
#define y
makeTRTBarrelCans.dx
tuple dx
Definition: makeTRTBarrelCans.py:20
comp_x
bool comp_x(const Point &lhs, const Point &rhs)
Definition: xAODChargedTracksWeightFilter.cxx:209