MINT2
Public Member Functions | Private Attributes | List of all members
RooEffResModel::CacheElem Class Reference
Inheritance diagram for RooEffResModel::CacheElem:

Public Member Functions

 CacheElem (const RooEffResModel &parent, const RooArgSet &iset, const TNamed *rangeName)
 
virtual ~CacheElem ()
 
virtual RooArgList containedArgs (Action)
 
Double_t getVal (const RooArgSet *nset=0) const
 

Private Attributes

std::vector< double > _bounds
 
RooRealVar * _x
 
RooAbsReal * _eff
 
RooRealVar * _xmin
 
RooRealVar * _xmax
 
RooAbsReal * _int
 
Double_t _val
 

Detailed Description

Definition at line 79 of file RooEffResModel.h.

Constructor & Destructor Documentation

◆ CacheElem()

RooEffResModel::CacheElem::CacheElem ( const RooEffResModel parent,
const RooArgSet &  iset,
const TNamed *  rangeName 
)

Definition at line 78 of file RooEffResModel.cpp.

79  :
80  _x(0), _eff(0), _xmin(0), _xmax(0), _int(0),
81  _val(std::numeric_limits<Double_t>::quiet_NaN())
82 {
83  RooRealVar& x = parent.convVar(); // binboundaries not const...
84  RooAbsReal& eff = *parent.efficiency();
85  RooAbsReal& model = parent.model();
86  // the subset of iset on which the efficiency depends
87  myunique_ptr<const RooArgSet> effInt( eff.getObservables(iset) );
88 
89  if (effInt->getSize()>1) {
90  std::cout << " got efficiency iset with more than 1 AbsArg -- not yet supported" << std::endl;
91  effInt->Print("V");
92  }
93  assert(effInt->getSize() < 2); // for now, we only do 1D efficiency histograms...
94  //TODO: instead of the above, verify whether things factorize, i.e.
95  // allow the case where the overlap of effInt and model is 1D, and
96  // all 'other' dependencies are from the efficiency only...
97  // That works because we can then ingrate the 'ceff' coefficient below
98  // over the remaining dependencies...
99  if (0 == effInt->getSize()) {
100  _int = parent.model().createIntegral(iset, RooNameReg::str(rangeName));
101  return;
102  }
103 
104  const char* rn = (rangeName ? RooNameReg::str(rangeName) : "");
105  // get bin bounds
106  const double rxmin = x.getMin(rn);
107  const double rxmax = x.getMax(rn);
108 
109  myunique_ptr<std::list<Double_t> > bounds(
110  eff.binBoundaries(x, x.getMin(), x.getMax()));
111  assert(bounds->size() > 1);
112  _bounds.reserve(bounds->size());
113  for (std::list<Double_t>::const_iterator
114  lo = bounds->begin(), hi = ++(bounds->begin());
115  hi != bounds->end(); ++hi, ++lo) {
116  if (*hi < rxmin) continue; // not there yet...
117  if (*lo > rxmax) break; // past the requested interval...
118  const double xmin = std::max(*lo, rxmin);
119  const double xmax = std::min(*hi, rxmax);
120  if (_bounds.empty())
121  _bounds.push_back(xmin);
122  _bounds.push_back(xmax);
123  }
124  assert(_bounds.size() > 1);
125  // build integral ingredients
126  _x = dynamic_cast<RooRealVar*>(x.clone((std::string(x.GetName()) + "_" +
127  rn).c_str()));
128  assert(_x);
129  RooCustomizer customizer2(model, (std::string(rn) + "_customizer2").c_str());
130  customizer2.replaceArg(x, *_x);
131  RooAbsReal* m = dynamic_cast<RooAbsReal*>(customizer2.build(false));
132  assert(m);
133  // build "customised" version of iset
134  RooArgSet custiset(iset);
135  custiset.replace(x, *_x);
136  // working range
137  _xmin = dynamic_cast<RooRealVar*>(_x->clone(
138  (std::string(_x->GetName()) + "_xmin").c_str()));
139  assert(_xmin);
140  _xmin->setVal(_bounds.front());
141  _xmax = dynamic_cast<RooRealVar*>(_x->clone(
142  (std::string(_x->GetName()) + "_xmax").c_str()));
143  assert(_xmax);
144  _xmax->setVal(_bounds.back());
145  std::string wrn(parent.GetName());
146  wrn += "_"; wrn += x.GetName(); wrn += "_"; wrn += model.GetName();
147  wrn += "_"; wrn += eff.GetName(); wrn += "_"; wrn += rn;
148  wrn += "_workRange";
149  assert(!_x->hasRange(wrn.c_str()));
150  _x->setRange(wrn.c_str(), *_xmin, *_xmax);
151  // build integral
152  _int = m->createIntegral(custiset, wrn.c_str());
153  assert(_int);
154  _int->addOwnedComponents(*m);
155  _int->addOwnedComponents(*_x);
156  _int->addOwnedComponents(*_xmin);
157  _int->addOwnedComponents(*_xmax);
158  // build efficiency in bin middle
159  RooCustomizer customizer(eff, (std::string(rn) + "_customizer").c_str());
160  customizer.replaceArg(x, *_x);
161  _eff = static_cast<RooAbsReal*>(customizer.build(false));
162  assert(_eff);
163 }
std::vector< double > _bounds
virtual RooResolutionModel & model() const
static const double m
virtual RooAbsReal * efficiency() const
Return pointer to pdf in product.

◆ ~CacheElem()

RooEffResModel::CacheElem::~CacheElem ( )
virtual

Definition at line 62 of file RooEffResModel.cpp.

63 {
64  delete _eff;
65  delete _int; // _int owns _x, _xmin, _xmax, so no need to free them
66 }

Member Function Documentation

◆ containedArgs()

RooArgList RooEffResModel::CacheElem::containedArgs ( Action  )
virtual

Definition at line 69 of file RooEffResModel.cpp.

70 {
71  // Return list of all RooAbsArgs in cache element
72  if (_eff) return RooArgList(*_int, *_eff, *_x, *_xmin, *_xmax);
73  else return RooArgList(*_int);
74 }

◆ getVal()

Double_t RooEffResModel::CacheElem::getVal ( const RooArgSet *  nset = 0) const

Definition at line 165 of file RooEffResModel.cpp.

166 {
167  if (0 == _x) {
168  // handle trivial case
169  return _int->getVal(nset);
170  }
171  // see if our cached value needs recalculating
172  if (_val != _val || _eff->isValueOrShapeDirtyAndClear() ||
173  _int->isValueOrShapeDirtyAndClear()) {
174  // yes, so iterate over subranges, and sum up integral contributions
175  _val = 0.;
176  for (unsigned i = 1; i < _bounds.size(); ++i) {
177  _xmin->setVal(_bounds[i - 1]);
178  _xmax->setVal(_bounds[i]);
179  _x->setVal(0.5 * (_bounds[i - 1] + _bounds[i]));
180  _val += _int->getVal() * _eff->getVal();
181  }
182  }
183 
184  return _val;
185 }
std::vector< double > _bounds

Member Data Documentation

◆ _bounds

std::vector<double> RooEffResModel::CacheElem::_bounds
private

Definition at line 91 of file RooEffResModel.h.

◆ _eff

RooAbsReal* RooEffResModel::CacheElem::_eff
private

Definition at line 93 of file RooEffResModel.h.

◆ _int

RooAbsReal* RooEffResModel::CacheElem::_int
private

Definition at line 96 of file RooEffResModel.h.

◆ _val

Double_t RooEffResModel::CacheElem::_val
mutableprivate

Definition at line 97 of file RooEffResModel.h.

◆ _x

RooRealVar* RooEffResModel::CacheElem::_x
private

Definition at line 92 of file RooEffResModel.h.

◆ _xmax

RooRealVar* RooEffResModel::CacheElem::_xmax
private

Definition at line 95 of file RooEffResModel.h.

◆ _xmin

RooRealVar* RooEffResModel::CacheElem::_xmin
private

Definition at line 94 of file RooEffResModel.h.


The documentation for this class was generated from the following files: