111using std::endl, std::string, std::ostream;
120 _coefNormMgr(this,10)
136 _convVar(
"!convVar",
"Convolution variable", this, cVar, false, false),
137 _convSet(
"!convSet",
"Set of resModel X basisFunc convolutions", this),
138 _coefNormMgr(this, 10),
150 _model{other._model ? static_cast<
RooResolutionModel *>(other._model->clone(other._model->GetName())) : nullptr},
152 _convVar(
"!convVar", this, other._convVar),
153 _convSet(
"!convSet", this, other._convSet),
154 _coefNormMgr(other._coefNormMgr, this),
155 _codeReg(other._codeReg)
173 for (
auto arg : tmp) {
243 coutE(InputArguments) <<
"RooAbsAnaConvPdf::declareBasis(" <<
GetName() <<
"): ERROR attempt to "
244 <<
" declare basis functions in a copied RooAbsAnaConvPdf" << std::endl ;
250 coutE(InputArguments) <<
"RooAbsAnaConvPdf::declareBasis(" <<
GetName() <<
"): resolution model "
251 <<
_model->
GetName() <<
" doesn't support basis function " << expression << std::endl;
257 basisArgs.
add(params) ;
259 TString basisName(expression) ;
260 for (
const auto arg : basisArgs) {
262 basisName.
Append(arg->GetName()) ;
265 auto basisFunc = std::make_unique<RooFormulaVar>(basisName, expression, basisArgs);
266 basisFunc->setAttribute(
"RooWorkspace::Recycle") ;
267 basisFunc->setOperMode(
operMode()) ;
273 coutE(InputArguments) <<
"RooAbsAnaConvPdf::declareBasis(" <<
GetName() <<
"): unable to construct convolution with basis function '"
274 << expression <<
"'" << std::endl ;
291 for (
auto *conv : static_range_cast<RooResolutionModel*>(
_convSet)) {
295 if (!newConvSet.
addOwned(std::move(newConv))) {
333 const RooArgSet* auxProto,
bool verbose)
const
340 modelDep->remove(*
convVar(),
true,
true) ;
341 Int_t numAddDep = modelDep->size() ;
348 if (numAddDep>0 || !pdfCanDir || !resCanDir) {
352 if (numAddDep>0) reason +=
"Resolution model has more observables than the convolution variable. " ;
353 if (!pdfCanDir) reason +=
"PDF does not support internal generation of convolution observable. " ;
354 if (!resCanDir) reason +=
"Resolution model does not support internal generation of convolution observable. " ;
356 coutI(Generation) <<
"RooAbsAnaConvPdf::genContext(" <<
GetName() <<
") Using regular accept/reject generator for convolution p.d.f because: " << reason.c_str() << std::endl ;
357 return new RooGenContext(*
this,vars,prototype,auxProto,verbose) ;
361 if (context)
return context;
393 if (!conv)
return nullptr;
410 for (
auto *conv : static_range_cast<RooAbsPdf*>(
_convSet)) {
413 const double c = conv->getVal(
nullptr);
414 cxcoutD(Eval) <<
"RooAbsAnaConvPdf::evaluate(" <<
GetName() <<
") val += coef*conv [" <<
index-1 <<
"/"
415 <<
_convSet.
size() <<
"] coef = " << coef <<
" conv = " <<
c << std::endl ;
444 if (allVars.
empty())
return 0 ;
451 std::unique_ptr<RooArgSet> normSet{normSet2 ?
getObservables(normSet2) :
nullptr};
453 RooArgSet intSetAll{allDeps,
"intSetAll"};
456 auto intCoefSet = std::make_unique<RooArgSet>(
"intCoefSet");
457 auto intConvSet = std::make_unique<RooArgSet>(
"intConvSet");
462 if (conv->dependsOn(*arg)) ok=
false ;
466 intCoefSet->add(*arg) ;
468 intConvSet->add(*arg) ;
474 auto normCoefSet = std::make_unique<RooArgSet>(
"normCoefSet");
475 auto normConvSet = std::make_unique<RooArgSet>(
"normConvSet");
480 if (conv->dependsOn(*arg)) ok=
false ;
484 normCoefSet->add(*arg) ;
486 normConvSet->add(*arg) ;
492 if (intCoefSet->empty()) intCoefSet.reset();
493 if (intConvSet->empty()) intConvSet.reset();
494 if (normCoefSet->empty()) normCoefSet.reset();
495 if (normConvSet->empty()) normConvSet.reset();
499 Int_t masterCode(0) ;
500 std::vector<Int_t> tmp(1, 0) ;
507 normConvSet.get()) + 1;
509 analVars.
add(allDeps) ;
555 RooArgSet *intCoefSet = retrieved.sets[0];
556 RooArgSet *intConvSet = retrieved.sets[1];
557 RooArgSet *normCoefSet = retrieved.sets[2];
558 RooArgSet *normConvSet = retrieved.sets[3];
562 if (normCoefSet ==
nullptr && normConvSet ==
nullptr) {
566 for (
auto *conv : static_range_cast<RooAbsPdf *>(
_convSet)) {
569 const double term = coef * conv->getNormObj(
nullptr, intConvSet, rangeNamePtr)->getVal();
571 cxcoutD(Eval) <<
"RooAbsAnaConv::aiWN(" <<
GetName() <<
") [" <<
index - 1 <<
"] integral += " << term
582 for (
auto *conv : static_range_cast<RooAbsPdf *>(
_convSet)) {
586 double term = conv->getNormObj(
nullptr, intConvSet, rangeNamePtr)->getVal();
587 integral += coefInt * term;
592 double term = conv->getNormObj(
nullptr, normConvSet)->getVal();
593 norm += coefNorm * term;
598 return integral / norm;
624 coutE(InputArguments) <<
"RooAbsAnaConvPdf::coefAnalyticalIntegral(" <<
GetName() <<
") ERROR: unrecognized integration code: " << code << std::endl ;
684 std::string
name = std::string{
GetName()} +
"_coefVar_" + std::to_string(i);
685 varList.
addOwned(std::make_unique<RooConvCoefVar>(
name.c_str(),
"coefVar",*
this,i,&*cvars));
697 std::vector<RooAbsArg*> tmp;
698 for (
auto arg : *cVars) {
700 if (convSetArg->dependsOn(*arg)) {
706 cVars->remove(tmp.begin(), tmp.end(),
true,
true);
724 os <<
indent <<
"--- RooAbsAnaConvPdf ---" << std::endl;
726 conv->printMultiline(os,contents,verbose,
indent) ;
731std::unique_ptr<RooAbsArg>
737 if (normSet.
empty()) {
738 return _convSet[0].compileForNormSet(normSet, ctx);
743 auto newArg = std::make_unique<RooFit::Detail::RooNormalizedPdf>(*pdfClone, normSet);
747 for (
RooAbsArg *server : newArg->servers()) {
748 server->setAttribute(
"_COMPILED");
750 newArg->setAttribute(
"_COMPILED");
751 newArg->addOwnedComponents(std::move(pdfClone));
759 if (normSet.
empty()) {
768 if (
auto convArgClone = ctx.
compile(*convArg, *pdfClone, {})) {
769 convArgClones.
add(*convArgClone);
772 pdfClone->redirectServers(convArgClones,
false,
true);
778 auto newArg = std::make_unique<RooFit::Detail::RooNormalizedPdf>(*pdfClone, normSet);
782 for (
RooAbsArg *server : newArg->servers()) {
783 server->setAttribute(
"_COMPILED");
785 newArg->setAttribute(
"_COMPILED");
786 newArg->addOwnedComponents(std::move(pdfClone));
static void indent(ostringstream &buf, int indent_level)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
int store(const std::vector< int > &codeList, RooArgSet *set1=nullptr, RooArgSet *set2=nullptr, RooArgSet *set3=nullptr, RooArgSet *set4=nullptr)
Store given arrays of integer codes, and up to four RooArgSets in the registry (each setX pointer may...
Output retrieve(int masterCode)
Retrieve the array of integer codes associated with the given master code, together with the (up to f...
Base class for PDFs that represent a physics model that can be analytically convolved with a resoluti...
friend class RooConvGenContext
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &analVars, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Advertise capability to perform (analytical) integrals internally.
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Return analytical integral defined by given code, which is returned by getAnalyticalIntegralWN()
virtual double coefAnalyticalIntegral(Int_t coef, Int_t code, const char *rangeName=nullptr) const
Default implementation of function implementing advertised integrals.
virtual bool changeModel(const RooResolutionModel &newModel)
Change the current resolution model to newModel.
double getCoefNorm(Int_t coefIdx, const RooArgSet &nset, const char *rangeName) const
bool forceAnalyticalInt(const RooAbsArg &dep) const override
This function forces RooRealIntegral to offer all integration dependents to RooAbsAnaConvPdf::getAnal...
RooAbsGenContext * genContext(const RooArgSet &vars, const RooDataSet *prototype=nullptr, const RooArgSet *auxProto=nullptr, bool verbose=false) const override
Create a generator context for this p.d.f.
RooResolutionModel * _model
Original resolution model (not a server)
virtual double coefficient(Int_t basisIndex) const =0
void ioStreamerPass2() override
Second-pass schema evolution, called by the RooWorkspace after reading.
RooArgList _basisList
! List of created basis functions
RooObjCacheManager _coefNormMgr
! Coefficient normalization manager
void makeCoefVarList(RooArgList &) const
Build complete list of coefficient variables.
RooAICRegistry _codeReg
! Registry of analytical integration codes
virtual Int_t getCoefAnalyticalIntegral(Int_t coef, RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=nullptr) const
Default implementation of function advertising integration capabilities.
bool _ownModel
Flag indicating ownership of _model.
~RooAbsAnaConvPdf() override
Destructor.
bool isDirectGenSafe(const RooAbsArg &arg) const override
Return true if it is safe to generate the convolution observable from the internal generator (this is...
RooAbsRealLValue * convVar()
Retrieve the convolution variable.
double evaluate() const override
Calculate the current unnormalized value of the PDF.
void printMultiline(std::ostream &stream, Int_t contents, bool verbose=false, TString indent="") const override
Print info about this object to the specified stream.
RooRealProxy _convVar
Convolution variable.
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive) override
Forward server redirection to the original resolution model.
RooAbsAnaConvPdf()
Default constructor, required for persistence.
Int_t declareBasis(const char *expression, const RooArgList ¶ms)
Declare a basis function for use in this physics model.
RooListProxy _convSet
Set of (resModel (x) basisFunc) convolution objects.
virtual RooFit::OwningPtr< RooArgSet > coefVars(Int_t coefIdx) const
Return set of parameters with are used exclusively by the coefficient functions.
std::unique_ptr< RooAbsArg > compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext &ctx) const override
Common abstract base class for objects that represent a value and a "shape" in RooFit.
RooFit::OwningPtr< RooArgSet > getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
void removeServer(RooAbsArg &server, bool force=false)
Unregister another RooAbsArg as a server to us, ie, declare that we no longer depend on its value and...
RooFit::OwningPtr< RooArgSet > getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
bool redirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool isRecursionStep=false)
Replace all direct servers of this object with the new servers in newServerList.
virtual void ioStreamerPass2()
Method called by workspace container to finalize schema evolution issues that cannot be handled in a ...
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
RooAbsArg * findServer(const char *name) const
Return server of this with name name. Returns nullptr if not found.
OperMode operMode() const
Query the operation mode of this node.
Abstract container object that can hold multiple RooAbsArg objects.
RooAbsCollection * snapshot(bool deepCopy=true) const
Take a snap shot of current collection contents.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Int_t index(const RooAbsArg *arg) const
Returns index of given arg, or -1 if arg is not in the collection.
const_iterator end() const
Storage_t::size_type size() const
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
const_iterator begin() const
Abstract base class for generator contexts of RooAbsPdf objects.
Abstract interface for all probability density functions.
std::unique_ptr< RooAbsArg > compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext &ctx) const override
virtual bool isDirectGenSafe(const RooAbsArg &arg) const
Check if given observable can be safely generated using the pdfs internal generator mechanism (if tha...
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Print multi line detailed information of this RooAbsPdf.
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursiveStep) override
Hook function intercepting redirectServer calls.
virtual Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, bool staticInitOK=true) const
Load generatedVars with the subset of directVars that we can generate events for, and return a code t...
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
Abstract base class for objects that represent a real value and implements functionality common to al...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
bool _forceNumInt
Force numerical integration if flag set.
RooFit::OwningPtr< RooAbsReal > createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}) const
Create an object that represents the integral of the function over one or more observables listed in ...
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
RooAbsArg * absArg() const
Return pointer to contained argument.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Int_t setObj(const RooArgSet *nset, T *obj, const TNamed *isetRangeName=nullptr)
Setter function without integration set.
T * getObj(const RooArgSet *nset, Int_t *sterileIndex=nullptr, const TNamed *isetRangeName=nullptr)
Getter function without integration set.
void removeAll() override
Remove all argument inset using remove(const RooAbsArg&).
bool addOwned(RooAbsArg &var, bool silent=false) override
Overloaded RooCollection_t::addOwned() method insert object into owning set and registers object as s...
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false) override
Remove object 'var' from set and deregister 'var' as server to owner.
Container class to hold unbinned data.
void compileServers(RooAbsArg &arg, RooArgSet const &normSet)
T * compile(T &arg, RooAbsArg &owner, RooArgSet const &normSet)
Implements a universal generator context for all RooAbsPdf classes that do not have or need a special...
static const char * str(const TNamed *ptr)
Return C++ string corresponding to given TNamed pointer.
static const TNamed * ptr(const char *stringPtr)
Return a unique TNamed pointer for given C++ string.
Variable that can be changed from the outside.
RooResolutionModel is the base class for PDFs that represent a resolution model that can be convolute...
virtual RooResolutionModel * convolution(RooFormulaVar *basis, RooAbsArg *owner) const
Instantiate a clone of this resolution model representing a convolution with given basis function.
bool isBasisSupported(const char *name) const
virtual RooAbsGenContext * modelGenContext(const RooAbsAnaConvPdf &, const RooArgSet &, const RooDataSet *, const RooArgSet *, bool) const
RooAbsRealLValue & convVar() const
Return the convolution variable of the resolution model.
TObject * clone(const char *newname=nullptr) const override=0
const T & arg() const
Return reference to object held in proxy.
Implements a RooResolution model that corresponds to a delta function.
The TNamed class is the base class for all named ROOT classes.
const char * GetName() const override
Returns name of object.
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
TString & Append(const char *cs)
T * OwningPtr
An alias for raw pointers for indicating that the return type of a RooFit function is an owning point...
OwningPtr< T > makeOwningPtr(std::unique_ptr< T > &&ptr)
Internal helper to turn a std::unique_ptr<T> into an OwningPtr.