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

#include <ChargedTracksWeightFilter.h>

Collaboration diagram for ChargedTracksWeightFilter::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 25 of file ChargedTracksWeightFilter.h.

Member Function Documentation

◆ get_minimum()

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

get minimum over certain range (requires initialization to extrapolate)

Definition at line 229 of file ChargedTracksWeightFilter.cxx.

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

◆ initialize()

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

Definition at line 252 of file ChargedTracksWeightFilter.cxx.

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

◆ value()

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

get value for certain x

Definition at line 208 of file ChargedTracksWeightFilter.cxx.

208  {
209 
210  const double dummy = -1;
211 
212  // find lowest weight in allowed range
213  auto lower = std::upper_bound(points.begin(), points.end(),
214  Point(nch, dummy, dummy), comp_x);
215 
216  if(lower != points.begin()) lower--;
217 
218  const auto & x = lower-> x;
219  const auto & y = lower-> y;;
220  const auto & slope = lower-> slope;;
221 
222  // weight using linear spline
223  const auto w_fc = (nch-x)*slope + y;
224 
225  if(w_fc<0) return 0; // extrapolation gives negative value
226  else return w_fc;
227 }

Member Data Documentation

◆ points

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

n-1 spline points filled at initialization

Definition at line 39 of file ChargedTracksWeightFilter.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
comp_x
bool comp_x(const Point &lhs, const Point &rhs)
Definition: ChargedTracksWeightFilter.cxx:200
x
#define x
Point
ChargedTracksWeightFilter::Spline::Point Point
Definition: ChargedTracksWeightFilter.cxx:11
makeTRTBarrelCans.y1
tuple y1
Definition: makeTRTBarrelCans.py:15
lumiFormat.i
int i
Definition: lumiFormat.py:92
python.xAODType.dummy
dummy
Definition: xAODType.py:4
ChargedTracksWeightFilter::Spline::points
std::vector< Point > points
n-1 spline points filled at initialization
Definition: ChargedTracksWeightFilter.h:39
comp_y
bool comp_y(const Point &lhs, const Point &rhs)
Definition: ChargedTracksWeightFilter.cxx:204
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
makeTRTBarrelCans.dy
tuple dy
Definition: makeTRTBarrelCans.py:21
y
#define y
makeTRTBarrelCans.dx
tuple dx
Definition: makeTRTBarrelCans.py:20
ChargedTracksWeightFilter::Spline::value
double value(int nch) const
get value for certain x
Definition: ChargedTracksWeightFilter.cxx:208