78 ClassImp(RooNumConvolution);
84 RooNumConvolution::RooNumConvolution() :
111 RooNumConvolution::RooNumConvolution(
const char *name,
const char *title, RooRealVar& convVar, RooAbsReal& inPdf, RooAbsReal& resmodel,
const RooNumConvolution* proto) :
112 RooAbsReal(name,title),
114 _convIntConfig(RooNumIntConfig::defaultConfig()),
117 _origVar(
"origVar",
"Original Convolution variable",this,convVar),
118 _origPdf(
"origPdf",
"Original Input PDF",this,inPdf),
119 _origModel(
"origModel",
"Original Resolution model",this,resmodel),
120 _ownedClonedPdfSet(
"ownedClonePdfSet"),
121 _ownedClonedModelSet(
"ownedCloneModelSet"),
127 _windowParam(
"windowParam",
"Convolution window parameter",this,kFALSE),
128 _verboseThresh(2000),
133 _convIntConfig.method1D().setLabel(
"RooAdaptiveGaussKronrodIntegrator1D") ;
134 _convIntConfig.method1DOpen().setLabel(
"RooAdaptiveGaussKronrodIntegrator1D") ;
137 convIntConfig() = proto->convIntConfig() ;
138 if (proto->_useWindow) {
139 setConvolutionWindow((RooAbsReal&)*proto->_windowParam.at(0),(RooAbsReal&)*proto->_windowParam.at(1),proto->_windowScale) ;
149 RooNumConvolution::RooNumConvolution(
const RooNumConvolution& other,
const char* name) :
150 RooAbsReal(other,name),
152 _convIntConfig(other._convIntConfig),
155 _origVar(
"origVar",this,other._origVar),
156 _origPdf(
"origPdf",this,other._origPdf),
157 _origModel(
"origModel",this,other._origModel),
158 _ownedClonedPdfSet(
"ownedClonePdfSet"),
159 _ownedClonedModelSet(
"ownedCloneModelSet"),
163 _useWindow(other._useWindow),
164 _windowScale(other._windowScale),
165 _windowParam(
"windowParam",this,other._windowParam),
166 _verboseThresh(other._verboseThresh),
167 _doProf(other._doProf),
168 _callHist(other._callHist)
177 void RooNumConvolution::initialize()
const
183 _ownedClonedPdfSet.removeAll() ;
184 _ownedClonedModelSet.removeAll() ;
186 if (_cloneVar)
delete _cloneVar ;
190 _cloneVar =
new RooRealVar(Form(
"%s_prime",_origVar.arg().GetName()),
"Convolution Variable",0) ;
192 RooCustomizer mgr1(pdf(),
"NumConv_PdfClone") ;
193 mgr1.setCloneBranchSet(_ownedClonedPdfSet) ;
194 mgr1.replaceArg(var(),*_cloneVar) ;
195 _clonePdf = (RooAbsReal*) mgr1.build() ;
197 RooCustomizer mgr2(model(),
"NumConv_ModelClone") ;
198 mgr2.setCloneBranchSet(_ownedClonedModelSet) ;
199 mgr2.replaceArg(var(),*_cloneVar) ;
200 _cloneModel = (RooAbsReal*) mgr2.build() ;
203 _cloneVar->SetName(var().GetName()) ;
206 _integrand =
new RooConvIntegrandBinding(*_clonePdf,*_cloneModel,*_cloneVar,var(),0) ;
209 _integrator = RooNumIntFactory::instance().createIntegrator(*_integrand,_convIntConfig,1) ;
210 _integrator->setUseIntegrandLimits(kFALSE) ;
221 RooNumConvolution::~RooNumConvolution()
230 Double_t RooNumConvolution::evaluate()
const
233 if (!_init) initialize() ;
236 Double_t x = _origVar ;
239 _integrand->setNormalizationSet(_origVar.nset()) ;
243 Double_t center = ((RooAbsReal*)_windowParam.at(0))->getVal() ;
244 Double_t width = _windowScale * ((RooAbsReal*)_windowParam.at(1))->getVal() ;
245 _integrator->setLimits(x-center-width,x-center+width) ;
247 _integrator->setLimits(-RooNumber::infinity(),RooNumber::infinity()) ;
251 if (_doProf) _integrand->resetNumCall() ;
252 Double_t ret = _integrator->integral(&x) ;
254 _callHist->Fill(x,_integrand->numCall()) ;
255 if (_integrand->numCall()>_verboseThresh) {
256 coutW(Integration) <<
"RooNumConvolution::eveluate(" << GetName() <<
") WARNING convolution integral at x=" << x
257 <<
" required " << _integrand->numCall() <<
" function evaluations" << endl ;
269 Bool_t RooNumConvolution::redirectServersHook(
const RooAbsCollection& , Bool_t ,
281 void RooNumConvolution::clearConvolutionWindow()
283 _useWindow = kFALSE ;
284 _windowParam.removeAll() ;
294 void RooNumConvolution::setConvolutionWindow(RooAbsReal& centerParam, RooAbsReal& widthParam, Double_t widthScaleFactor)
297 _windowParam.removeAll() ;
298 _windowParam.add(centerParam) ;
299 _windowParam.add(widthParam) ;
300 _windowScale = widthScaleFactor ;
309 void RooNumConvolution::setCallWarning(Int_t threshold)
312 coutE(InputArguments) <<
"RooNumConvolution::setCallWarning(" << GetName() <<
") ERROR: threshold must be positive, value unchanged" << endl ;
315 _verboseThresh = threshold ;
331 void RooNumConvolution::setCallProfiling(Bool_t flag, Int_t nbinX, Int_t nbinCall, Int_t nCallHigh)
337 _callHist =
new TH2F(Form(
"callHist_%s",GetName()),Form(
"Call Profiling of RooNumConvolution %s",GetTitle()),
338 nbinX,_origVar.min(),_origVar.max(),
339 nbinCall,0,nCallHigh) ;
342 }
else if (_doProf) {
357 void RooNumConvolution::printCompactTreeHook(ostream& os,
const char* indent)
359 os << indent <<
"RooNumConvolution begin cache" << endl ;
362 _cloneVar->printCompactTree(os,Form(
"%s[Var]",indent)) ;
363 _clonePdf->printCompactTree(os,Form(
"%s[Pdf]",indent)) ;
364 _cloneModel->printCompactTree(os,Form(
"%s[Mod]",indent)) ;
367 os << indent <<
"RooNumConvolution end cache" << endl ;