Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
RooLinTransBinning.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17/**
18\file RooLinTransBinning.cxx
19\class RooLinTransBinning
20\ingroup Roofitcore
21
22Special binning implementation for RooLinearVar
23that transforms the binning of the RooLinearVar input variable in the same
24way that RooLinearVar does
25**/
26
27#include "RooLinTransBinning.h"
28
29#include <stdexcept>
30
31
32
33////////////////////////////////////////////////////////////////////////////////
34/// Constructor with a given input binning and the slope and offset to be applied to
35/// construct the linear transformation
36
37RooLinTransBinning::RooLinTransBinning(const RooAbsBinning& input, double slope, double offset, const char* name) :
39{
40 updateInput(input,slope,offset) ;
41}
42
43
44
45////////////////////////////////////////////////////////////////////////////////
46/// Copy constructor
47
52
53////////////////////////////////////////////////////////////////////////////////
54
55void RooLinTransBinning::setRange(double /*xlo*/, double /*xhi*/)
56{
57 // Change limits -- not implemented
58}
59
60
61////////////////////////////////////////////////////////////////////////////////
62/// Return array of bin boundaries
63
65{
66 const int n = numBoundaries();
67 // Return array with boundary values
68 _array.resize(n);
69
70 const double* inputArray = _input->array() ;
71
72 if (_slope>0) {
73 for (int i=0; i < n; i++) {
74 _array[i] = trans(inputArray[i]) ;
75 }
76 } else {
77 for (int i=0; i < n; i++) {
78 _array[i] = trans(inputArray[n-i-1]) ;
79 }
80 }
81
82 return _array.data();
83}
84
85
86
87////////////////////////////////////////////////////////////////////////////////
88/// Update the slope and offset parameters and the pointer to the input binning
89
90void RooLinTransBinning::updateInput(const RooAbsBinning& input, double slope, double offset)
91{
92 _input = const_cast<RooAbsBinning*>(&input);
93 _slope = slope ;
94 _offset = offset ;
95}
96
97
98void RooLinTransBinning::binNumbers(double const * x, int * bins, std::size_t n, int coef) const
99{
100 // We are not allowed to modify the input array, so we can't apply the
101 // transformation in-place and then call _input->binNumbers() without
102 // allocating additional memory. That's why we fall back to binNumber() for
103 // now. The RooLinTransBinning is only ever used in the RooLinearVar, so if
104 // this ever becomes a bottleneck this could be optimized.
105 for(std::size_t i = 0; i < n; ++i) {
106 bins[i] += coef * _input->binNumber(invTrans(x[i]));
107 }
108}
char name[80]
Definition TGX11.cxx:148
RooAbsBinning(const char *name=nullptr)
RooAbsBinning * _input
Input binning.
void updateInput(const RooAbsBinning &input, double slope=1.0, double offset=0.0)
Update the slope and offset parameters and the pointer to the input binning.
Int_t numBoundaries() const override
std::vector< double > _array
! Array of transformed bin boundaries
double trans(double x) const
void binNumbers(double const *x, int *bins, std::size_t n, int coef) const override
Compute the bin indices for multiple values of x.
double * array() const override
Return array of bin boundaries.
void setRange(double xlo, double xhi) override
double _offset
Offset of transformation.
RooLinTransBinning(const char *name=nullptr)
double invTrans(double x) const
double _slope
Slope of transformation.
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16