77using std::endl, std::string, std::ostream;
100 _convVar(
"!convVar",
"Convolution variable",this,cVar,false,false),
101 _convSet(
"!convSet",
"Set of resModel X basisFunc convolutions",this),
122 _model.absArg()->setAttribute(
"NOCacheAndTrack") ;
137 for (
auto arg : tmp) {
162 coutE(InputArguments) <<
"RooAbsAnaConvPdf::declareBasis(" <<
GetName() <<
"): ERROR attempt to "
163 <<
" declare basis functions in a copied RooAbsAnaConvPdf" << std::endl ;
169 coutE(InputArguments) <<
"RooAbsAnaConvPdf::declareBasis(" <<
GetName() <<
"): resolution model "
170 <<
_model.absArg()->GetName()
171 <<
" doesn't support basis function " << expression << std::endl ;
177 basisArgs.
add(params) ;
179 TString basisName(expression) ;
180 for (
const auto arg : basisArgs) {
182 basisName.
Append(arg->GetName()) ;
185 auto basisFunc = std::make_unique<RooFormulaVar>(basisName, expression, basisArgs);
186 basisFunc->setAttribute(
"RooWorkspace::Recycle") ;
187 basisFunc->setAttribute(
"NOCacheAndTrack") ;
188 basisFunc->setOperMode(
operMode()) ;
194 coutE(InputArguments) <<
"RooAbsAnaConvPdf::declareBasis(" <<
GetName() <<
"): unable to construct convolution with basis function '"
195 << expression <<
"'" << std::endl ;
217 if (!newConvSet.
addOwned(std::move(newConv))) {
230 _convSet.addOwned(std::move(newConvSet));
232 const std::string attrib = std::string(
"ORIGNAME:") +
_model->GetName();
233 const bool oldAttrib = newModel.
getAttribute(attrib.c_str());
255 const RooArgSet* auxProto,
bool verbose)
const
261 std::unique_ptr<RooArgSet> modelDep {
_model->getObservables(&vars)};
262 modelDep->remove(*
convVar(),
true,
true) ;
263 Int_t numAddDep = modelDep->size() ;
270 if (numAddDep>0 || !pdfCanDir || !resCanDir) {
274 if (numAddDep>0) reason +=
"Resolution model has more observables than the convolution variable. " ;
275 if (!pdfCanDir) reason +=
"PDF does not support internal generation of convolution observable. " ;
276 if (!resCanDir) reason +=
"Resolution model does not support internal generation of convolution observable. " ;
278 coutI(Generation) <<
"RooAbsAnaConvPdf::genContext(" <<
GetName() <<
") Using regular accept/reject generator for convolution p.d.f because: " << reason.c_str() << std::endl ;
279 return new RooGenContext(*
this,vars,prototype,auxProto,verbose) ;
283 if (context)
return context;
316 if (!conv)
return nullptr;
334 auto conv =
static_cast<RooAbsPdf*
>(convArg);
337 const double c = conv->getVal(
nullptr);
338 cxcoutD(Eval) <<
"RooAbsAnaConvPdf::evaluate(" <<
GetName() <<
") val += coef*conv [" << index-1 <<
"/"
339 <<
_convSet.size() <<
"] coef = " << coef <<
" conv = " <<
c << std::endl ;
342 cxcoutD(Eval) <<
"RooAbsAnaConvPdf::evaluate(" <<
GetName() <<
") [" << index-1 <<
"/" <<
_convSet.size() <<
"] coef = 0" << std::endl ;
368 if (allVars.
empty())
return 0 ;
375 std::unique_ptr<RooArgSet> normSet{normSet2 ?
getObservables(normSet2) :
nullptr};
377 RooArgSet intSetAll{allDeps,
"intSetAll"};
380 auto intCoefSet = std::make_unique<RooArgSet>(
"intCoefSet");
381 auto intConvSet = std::make_unique<RooArgSet>(
"intConvSet");
386 if (conv->dependsOn(*arg)) ok=false ;
390 intCoefSet->add(*arg) ;
392 intConvSet->add(*arg) ;
398 auto normCoefSet = std::make_unique<RooArgSet>(
"normCoefSet");
399 auto normConvSet = std::make_unique<RooArgSet>(
"normConvSet");
404 if (conv->dependsOn(*arg)) ok=false ;
408 normCoefSet->add(*arg) ;
410 normConvSet->add(*arg) ;
416 if (intCoefSet->empty()) intCoefSet.reset();
417 if (intConvSet->empty()) intConvSet.reset();
418 if (normCoefSet->empty()) normCoefSet.reset();
419 if (normConvSet->empty()) normConvSet.reset();
423 Int_t masterCode(0) ;
424 std::vector<Int_t> tmp(1, 0) ;
428 intCoefSet.release(),
429 intConvSet.release(),
430 normCoefSet.release(),
431 normConvSet.release()) + 1;
433 analVars.
add(allDeps) ;
482 _codeReg.retrieve(code - 1, intCoefSet, intConvSet, normCoefSet, normConvSet);
486 if (normCoefSet ==
nullptr && normConvSet ==
nullptr) {
491 double coef =
getCoefNorm(index++, intCoefSet, rangeNamePtr);
493 const double term = coef * conv->getNormObj(
nullptr, intConvSet, rangeNamePtr)->getVal();
495 cxcoutD(Eval) <<
"RooAbsAnaConv::aiWN(" <<
GetName() <<
") [" << index - 1 <<
"] integral += " << term
508 double coefInt =
getCoefNorm(index, intCoefSet, rangeNamePtr);
510 double term = conv->getNormObj(
nullptr, intConvSet, rangeNamePtr)->getVal();
511 integral += coefInt * term;
516 double term = conv->getNormObj(
nullptr, normConvSet)->getVal();
517 norm += coefNorm * term;
522 return integral / norm;
548 coutE(InputArguments) <<
"RooAbsAnaConvPdf::coefAnalyticalIntegral(" <<
GetName() <<
") ERROR: unrecognized integration code: " << code << std::endl ;
606 for (std::size_t i=0 ; i<
_convSet.size() ; i++) {
608 std::string
name = std::string{
GetName()} +
"_coefVar_" + std::to_string(i);
609 varList.
addOwned(std::make_unique<RooConvCoefVar>(
name.c_str(),
"coefVar",*
this,i,&*cvars));
621 std::vector<RooAbsArg*> tmp;
622 for (
auto arg : *cVars) {
624 if (convSetArg->dependsOn(*arg)) {
630 cVars->remove(tmp.begin(), tmp.end(),
true,
true);
648 os <<
indent <<
"--- RooAbsAnaConvPdf ---" << std::endl;
650 conv->printMultiline(os,contents,verbose,
indent) ;
660 if (carg->canNodeBeCached()==
Always) {
661 trackNodes.
add(*carg) ;
667std::unique_ptr<RooAbsArg>
673 if (normSet.
empty()) {
674 return _convSet[0].compileForNormSet(normSet, ctx);
679 auto newArg = std::make_unique<RooFit::Detail::RooNormalizedPdf>(*pdfClone, normSet);
683 for (
RooAbsArg *server : newArg->servers()) {
684 server->setAttribute(
"_COMPILED");
686 newArg->setAttribute(
"_COMPILED");
687 newArg->addOwnedComponents(std::move(pdfClone));
695 if (normSet.
empty()) {
704 if (
auto convArgClone = ctx.
compile(*convArg, *pdfClone, {})) {
705 convArgClones.
add(*convArgClone);
708 pdfClone->redirectServers(convArgClones,
false,
true);
714 auto newArg = std::make_unique<RooFit::Detail::RooNormalizedPdf>(*pdfClone, normSet);
718 for (
RooAbsArg *server : newArg->servers()) {
719 server->setAttribute(
"_COMPILED");
721 newArg->setAttribute(
"_COMPILED");
722 newArg->addOwnedComponents(std::move(pdfClone));
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
int Int_t
Signed integer 4 bytes (int).
static void indent(ostringstream &buf, int indent_level)
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
void setCacheAndTrackHints(RooArgSet &) override
Label OK'ed components with cache-and-track.
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.
virtual double coefficient(Int_t basisIndex) const =0
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.
~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.
RooRealProxy _model
Original model.
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.
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
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...
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.
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
RooAbsArg()
Default constructor.
OperMode operMode() const
Query the operation mode of this node.
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.
Storage_t::size_type size() const
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
Abstract base class for generator contexts of RooAbsPdf objects.
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.
RooAbsPdf()
Default constructor.
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 ...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
bool _forceNumInt
Force numerical integration if flag set.
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.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
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.
virtual RooAbsGenContext * modelGenContext(const RooAbsAnaConvPdf &, const RooArgSet &, const RooDataSet *, const RooArgSet *, bool) const
RooAbsRealLValue & convVar() const
Return the convolution variable of the resolution model.
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.