38 #include <RooCustomizer.h> 39 #include <RooStringVar.h> 40 class RooAbsAnaConvPdf;
46 #if __cplusplus < 201102L 47 #define myunique_ptr std::auto_ptr 54 #if __cplusplus < 201102L 55 #define myunique_ptr std::auto_ptr 72 if (
_eff)
return RooArgList(*_int, *
_eff, *_x, *_xmin, *_xmax);
73 else return RooArgList(*_int);
79 const TNamed* rangeName) :
80 _x(0),
_eff(0), _xmin(0), _xmax(0), _int(0),
81 _val(std::numeric_limits<Double_t>::quiet_NaN())
83 RooRealVar& x = parent.convVar();
87 myunique_ptr<const RooArgSet> effInt( eff.getObservables(iset) );
89 if (effInt->getSize()>1) {
90 std::cout <<
" got efficiency iset with more than 1 AbsArg -- not yet supported" << std::endl;
93 assert(effInt->getSize() < 2);
99 if (0 == effInt->getSize()) {
100 _int = parent.
model().createIntegral(iset, RooNameReg::str(rangeName));
104 const char* rn = (rangeName ? RooNameReg::str(rangeName) :
"");
106 const double rxmin = x.getMin(rn);
107 const double rxmax = x.getMax(rn);
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;
117 if (*lo > rxmax)
break;
118 const double xmin = std::max(*lo, rxmin);
119 const double xmax = std::min(*hi, rxmax);
126 _x = dynamic_cast<RooRealVar*>(x.clone((std::string(x.GetName()) +
"_" +
129 RooCustomizer customizer2(
model, (std::string(rn) +
"_customizer2").c_str());
130 customizer2.replaceArg(x, *
_x);
131 RooAbsReal*
m = dynamic_cast<RooAbsReal*>(customizer2.build(
false));
134 RooArgSet custiset(iset);
135 custiset.replace(x, *
_x);
137 _xmin = dynamic_cast<RooRealVar*>(
_x->clone(
138 (std::string(
_x->GetName()) +
"_xmin").c_str()));
141 _xmax = dynamic_cast<RooRealVar*>(
_x->clone(
142 (std::string(
_x->GetName()) +
"_xmax").c_str()));
145 std::string wrn(parent.GetName());
146 wrn +=
"_"; wrn += x.GetName(); wrn +=
"_"; wrn +=
model.GetName();
147 wrn +=
"_"; wrn += eff.GetName(); wrn +=
"_"; wrn += rn;
149 assert(!
_x->hasRange(wrn.c_str()));
152 _int =
m->createIntegral(custiset, wrn.c_str());
154 _int->addOwnedComponents(*
m);
155 _int->addOwnedComponents(*
_x);
159 RooCustomizer customizer(eff, (std::string(rn) +
"_customizer").c_str());
160 customizer.replaceArg(x, *
_x);
161 _eff = static_cast<RooAbsReal*>(customizer.build(
false));
169 return _int->getVal(nset);
172 if (_val != _val ||
_eff->isValueOrShapeDirtyAndClear() ||
173 _int->isValueOrShapeDirtyAndClear()) {
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();
189 RooResolutionModel& __model, RooAbsReal& eff) :
190 RooResolutionModel(name,title,__model.convVar())
192 ,
_model(
"!model",
"Original resolution model",this,__model)
193 ,
_eff(
"!efficiency",
"efficiency of convvar", this,eff)
202 RooResolutionModel(other,name)
203 , _observables(
"observables", this, other._observables)
204 , _model(
"!model", this, other._model)
205 , _eff(
"!efficiency", this, other._eff)
206 , _cacheMgr(other._cacheMgr, this)
224 {
return static_cast<RooAbsReal*>(
_eff.absArg()); }
227 {
return std::vector<RooAbsReal*>(1,
efficiency()); }
230 {
return dynamic_cast<RooResolutionModel&>(*
_model.absArg()); }
234 RooFormulaVar* inBasis, RooAbsArg* owner)
const 246 if (inBasis->getParameter(0) != x.absArg()) {
247 coutE(InputArguments) <<
"RooEffResModel::convolution(" << GetName() <<
"," <<
this 248 <<
") convolution parameter of basis function and PDF don't match" << endl
249 <<
"basis->findServer(0) = " << inBasis->findServer(0) << endl
250 <<
"x.absArg() = " << x.absArg() << endl;
255 coutE(InputArguments) <<
"RooEffResModel::convolution(" << GetName() <<
"," <<
this 256 <<
") basis function '" << inBasis->GetTitle() <<
"' is not supported." << endl;
260 std::string newName(GetName());
262 newName += inBasis->GetName();
264 newName += owner->GetName();
267 RooResolutionModel *conv =
model().convolution(inBasis, owner);
269 std::string newTitle(conv->GetTitle());
270 newTitle +=
" convoluted with basis function ";
271 newTitle += inBasis->GetName();
272 conv->SetTitle(newTitle.c_str());
276 effConv->addOwnedComponents(*conv);
277 effConv->changeBasis(inBasis);
279 const char* cacheParamsStr = getStringAttribute(
"CACHEPARAMINT");
280 if (cacheParamsStr && strlen(cacheParamsStr)) {
284 effConv->setStringAttribute(
"CACHEPARAMINT",cacheParamsStr);
295 return model().basisCode(name);
301 Double_t mod =
model().getVal();
318 RooArgSet& allVars, RooArgSet& analVars,
const char* rangeName)
const 320 if (_forceNumInt)
return 0;
321 analVars.add(allVars);
322 getCache(&analVars, RooNameReg::ptr(rangeName));
328 Int_t code,
const char* rangeName)
const 333 myunique_ptr<RooArgSet> vars(getParameters(RooArgSet()));
334 myunique_ptr<RooArgSet> iset(
335 _cacheMgr.nameSet1ByIndex(code - 1)->select(*vars));
336 cache =
getCache(iset.get(), RooNameReg::ptr(rangeName));
344 const RooAbsAnaConvPdf& convPdf,
const RooArgSet &vars,
345 const RooDataSet *prototype,
const RooArgSet* auxProto,
346 Bool_t verbose)
const 353 const RooArgSet& directVars, RooArgSet &generateVars,
354 Bool_t staticInitOK)
const 356 return model().getGenerator(directVars, generateVars, staticInitOK);
362 model().initGenerator(code);
369 model().generateEvent(code);
374 const char* rangeName)
const 376 rangeName = rangeName ? rangeName :
"default";
377 RangeMap::const_iterator it =
_ranges.find(rangeName);
378 if (it !=
_ranges.end())
return *it->second;
380 RooRealVar& x = static_cast<RooRealVar&>(convVar());
381 const Double_t xmin = x.getMin(rangeName);
382 const Double_t xmax = x.getMax(rangeName);
384 RooArgList* ranges =
new RooArgList;
385 myunique_ptr<std::list<Double_t> > bounds(
efficiency()->binBoundaries(x, x.getMin(), x.getMax()));
388 s +=
"RooEffResModel(";
s += GetName();
s +=
"): specified efficiency ";
389 s +=
efficiency()->GetName();
s +=
" does not provide binBoundaries...";
390 std::cout <<
s << std::endl;
393 std::list<Double_t>::const_iterator lo, hi = bounds->begin();
394 std::stringstream strange;
395 for (
unsigned int i = 0; i + 1 < bounds->size();++i) {
397 if (*hi < xmin)
continue;
398 if (*lo > xmax)
break;
399 const Double_t thisxmin = std::max(*lo, xmin);
400 const Double_t thisxmax = std::min(*hi, xmax);
404 strange << i <<
"_" << x.GetName() <<
"_" <<
efficiency()->GetName();
407 if (rangeName) strange <<
"_" << rangeName;
408 strange <<
"_I_" << RooNameSet(iset).content();
409 const std::string trange = strange.str();
410 const char* range = trange.c_str();
414 if (!x.hasRange(range)) {
415 x.setRange(range, thisxmin, thisxmax);
417 assert(x.getMin(range)==thisxmin);
418 assert(x.getMax(range)==thisxmax);
419 ranges->addOwned(*
new RooStringVar(range, range, range));
421 std::pair<RangeMap::iterator, bool> r =
_ranges.insert(
422 std::make_pair(std::string(rangeName), ranges));
424 return *r.first->second;
429 const RooArgSet *iset,
const TNamed *rangeName)
const 431 Int_t sterileIndex(-1);
433 if (cache)
return cache;
virtual void generateEvent(Int_t code)
virtual Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=0) const
std::vector< double > _bounds
virtual RooArgSet * observables() const
Return pointer to pdf in product.
virtual RooResolutionModel & model() const
const RooArgList & getIntegralRanges(const RooArgSet &iset, const char *rangeName=0) const
virtual Double_t evaluate() const
virtual RooEffResModel * convolution(RooFormulaVar *inBasis, RooAbsArg *owner) const
virtual Bool_t forceAnalyticalInt(const RooAbsArg &dep) const
virtual std::vector< RooAbsReal * > efficiencies() const
Return pointer to pdf in product.
virtual Int_t basisCode(const char *name) const
virtual RooEffResModel * clone(const char *newname) const
virtual void initGenerator(Int_t code)
virtual Double_t analyticalIntegral(Int_t code, const char *rangeName) const
Double_t getVal(const RooArgSet *nset=0) const
virtual ~RooEffResModel()
CacheElem(const RooEffResModel &parent, const RooArgSet &iset, const TNamed *rangeName)
virtual RooAbsReal * efficiency() const
Return pointer to pdf in product.
virtual RooArgList containedArgs(Action)
virtual RooAbsGenContext * modelGenContext(const RooAbsAnaConvPdf &convPdf, const RooArgSet &vars, const RooDataSet *prototype=0, const RooArgSet *auxProto=0, Bool_t verbose=kFALSE) const
CacheElem * getCache(const RooArgSet *iset, const TNamed *rangeName=0) const
RooObjCacheManager _cacheMgr
virtual Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, Bool_t staticInitOK=kTRUE) const