// RooConvGenContext is an efficient implementation of the generator context
// specific for RooAbsAnaConvPdf objects. The physics model is generated
// with a truth resolution model and the requested resolution model is generated
// separately as a PDF. The convolution variable of the physics model is
// subsequently explicitly smeared with the resolution model distribution.
// END_HTML
#include "RooFit.h"
#include "RooMsgService.h"
#include "RooConvGenContext.h"
#include "RooAbsAnaConvPdf.h"
#include "RooNumConvPdf.h"
#include "RooFFTConvPdf.h"
#include "RooProdPdf.h"
#include "RooDataSet.h"
#include "RooArgSet.h"
#include "RooTruthModel.h"
#include "Riostream.h"
ClassImp(RooConvGenContext)
;
RooConvGenContext::RooConvGenContext(const RooAbsAnaConvPdf &model, const RooArgSet &vars,
const RooDataSet *prototype, const RooArgSet* auxProto, Bool_t verbose) :
RooAbsGenContext(model,vars,prototype,auxProto,verbose), _pdfVarsOwned(0), _modelVarsOwned(0)
{
cxcoutI(Generation) << "RooConvGenContext::ctor() setting up special generator context for analytical convolution p.d.f. " << model.GetName()
<< " for generation of observable(s) " << vars << endl ;
_pdfCloneSet = (RooArgSet*) RooArgSet(model).snapshot(kTRUE) ;
if (!_pdfCloneSet) {
coutE(Generation) << "RooConvGenContext::RooConvGenContext(" << GetName() << ") Couldn't deep-clone PDF, abort," << endl ;
RooErrorHandler::softAbort() ;
}
RooAbsAnaConvPdf* pdfClone = (RooAbsAnaConvPdf*) _pdfCloneSet->find(model.GetName()) ;
RooTruthModel truthModel("truthModel","Truth resolution model",(RooRealVar&)*pdfClone->convVar()) ;
pdfClone->changeModel(truthModel) ;
((RooRealVar*)pdfClone->convVar())->removeRange() ;
_pdfVars = (RooArgSet*) pdfClone->getObservables(&vars) ; ;
_pdfGen = pdfClone->genContext(*_pdfVars,prototype,auxProto,verbose) ;
_modelCloneSet = (RooArgSet*) RooArgSet(*model._convSet.at(0)).snapshot(kTRUE) ;
if (!_modelCloneSet) {
coutE(Generation) << "RooConvGenContext::RooConvGenContext(" << GetName() << ") Couldn't deep-clone resolution model, abort," << endl ;
RooErrorHandler::softAbort() ;
}
RooResolutionModel* modelClone = (RooResolutionModel*)
_modelCloneSet->find(model._convSet.at(0)->GetName())->Clone("smearing") ;
_modelCloneSet->addOwned(*modelClone) ;
modelClone->changeBasis(0) ;
modelClone->convVar().removeRange() ;
_modelVars = (RooArgSet*) modelClone->getObservables(&vars) ;
_modelVars->add(modelClone->convVar()) ;
_convVarName = modelClone->convVar().GetName() ;
_modelGen = modelClone->genContext(*_modelVars,prototype,auxProto,verbose) ;
if (prototype) {
_pdfVars->add(*prototype->get()) ;
_modelVars->add(*prototype->get()) ;
}
if (auxProto) {
_pdfVars->add(*auxProto) ;
_modelVars->add(*auxProto) ;
}
}
RooConvGenContext::RooConvGenContext(const RooNumConvPdf &model, const RooArgSet &vars,
const RooDataSet *prototype, const RooArgSet* auxProto, Bool_t verbose) :
RooAbsGenContext(model,vars,prototype,auxProto,verbose)
{
cxcoutI(Generation) << "RooConvGenContext::ctor() setting up special generator context for numeric convolution p.d.f. " << model.GetName()
<< " for generation of observable(s) " << vars << endl ;
_pdfVarsOwned = (RooArgSet*) model.conv().clonePdf().getObservables(&vars)->snapshot(kTRUE) ;
_pdfVars = new RooArgSet(*_pdfVarsOwned) ;
_pdfGen = ((RooAbsPdf&)model.conv().clonePdf()).genContext(*_pdfVars,prototype,auxProto,verbose) ;
_pdfCloneSet = 0 ;
_modelVarsOwned = (RooArgSet*) model.conv().cloneModel().getObservables(&vars)->snapshot(kTRUE) ;
_modelVars = new RooArgSet(*_modelVarsOwned) ;
_convVarName = model.conv().cloneVar().GetName() ;
_modelGen = ((RooAbsPdf&)model.conv().cloneModel()).genContext(*_modelVars,prototype,auxProto,verbose) ;
_modelCloneSet = 0 ;
if (prototype) {
_pdfVars->add(*prototype->get()) ;
_modelVars->add(*prototype->get()) ;
}
}
RooConvGenContext::RooConvGenContext(const RooFFTConvPdf &model, const RooArgSet &vars,
const RooDataSet *prototype, const RooArgSet* auxProto, Bool_t verbose) :
RooAbsGenContext(model,vars,prototype,auxProto,verbose)
{
cxcoutI(Generation) << "RooConvGenContext::ctor() setting up special generator context for fft convolution p.d.f. " << model.GetName()
<< " for generation of observable(s) " << vars << endl ;
_convVarName = model._x.arg().GetName() ;
_pdfCloneSet = (RooArgSet*) RooArgSet(model._pdf1.arg()).snapshot(kTRUE) ;
RooAbsPdf* pdfClone = (RooAbsPdf*) _pdfCloneSet->find(model._pdf1.arg().GetName()) ;
RooRealVar* cvPdf = (RooRealVar*) _pdfCloneSet->find(model._x.arg().GetName()) ;
cvPdf->removeRange() ;
RooArgSet* tmp1 = pdfClone->getObservables(&vars) ;
_pdfVarsOwned = (RooArgSet*) tmp1->snapshot(kTRUE) ;
_pdfVars = new RooArgSet(*_pdfVarsOwned) ;
_pdfGen = pdfClone->genContext(*_pdfVars,prototype,auxProto,verbose) ;
_modelCloneSet = (RooArgSet*) RooArgSet(model._pdf2.arg()).snapshot(kTRUE) ;
RooAbsPdf* modelClone = (RooAbsPdf*) _modelCloneSet->find(model._pdf2.arg().GetName()) ;
RooRealVar* cvModel = (RooRealVar*) _modelCloneSet->find(model._x.arg().GetName()) ;
cvModel->removeRange() ;
RooArgSet* tmp2 = modelClone->getObservables(&vars) ;
_modelVarsOwned = (RooArgSet*) tmp2->snapshot(kTRUE) ;
_modelVars = new RooArgSet(*_modelVarsOwned) ;
_modelGen = modelClone->genContext(*_pdfVars,prototype,auxProto,verbose) ;
delete tmp1 ;
delete tmp2 ;
if (prototype) {
_pdfVars->add(*prototype->get()) ;
_modelVars->add(*prototype->get()) ;
}
}
RooConvGenContext::~RooConvGenContext()
{
delete _pdfGen ;
delete _modelGen ;
delete _pdfCloneSet ;
delete _modelCloneSet ;
delete _modelVars ;
delete _pdfVars ;
delete _pdfVarsOwned ;
delete _modelVarsOwned ;
}
void RooConvGenContext::attach(const RooArgSet& args)
{
RooRealVar* cvModel = (RooRealVar*) _modelVars->find(_convVarName) ;
RooRealVar* cvPdf = (RooRealVar*) _pdfVars->find(_convVarName) ;
RooArgSet* pdfCommon = (RooArgSet*) args.selectCommon(*_pdfVars) ;
pdfCommon->remove(*cvPdf,kTRUE,kTRUE) ;
RooArgSet* modelCommon = (RooArgSet*) args.selectCommon(*_modelVars) ;
modelCommon->remove(*cvModel,kTRUE,kTRUE) ;
_pdfGen->attach(*pdfCommon) ;
_modelGen->attach(*modelCommon) ;
delete pdfCommon ;
delete modelCommon ;
}
void RooConvGenContext::initGenerator(const RooArgSet &theEvent)
{
_cvModel = (RooRealVar*) _modelVars->find(_convVarName) ;
_cvPdf = (RooRealVar*) _pdfVars->find(_convVarName) ;
_cvOut = (RooRealVar*) theEvent.find(_convVarName) ;
RooArgSet* pdfCommon = (RooArgSet*) theEvent.selectCommon(*_pdfVars) ;
pdfCommon->remove(*_cvPdf,kTRUE,kTRUE) ;
_pdfVars->replace(*pdfCommon) ;
delete pdfCommon ;
RooArgSet* modelCommon = (RooArgSet*) theEvent.selectCommon(*_modelVars) ;
modelCommon->remove(*_cvModel,kTRUE,kTRUE) ;
_modelVars->replace(*modelCommon) ;
delete modelCommon ;
_pdfGen->initGenerator(*_pdfVars) ;
_modelGen->initGenerator(*_modelVars) ;
}
void RooConvGenContext::generateEvent(RooArgSet &theEvent, Int_t remaining)
{
while(1) {
_modelGen->generateEvent(*_modelVars,remaining) ;
_pdfGen->generateEvent(*_pdfVars,remaining) ;
Double_t convValSmeared = _cvPdf->getVal() + _cvModel->getVal() ;
if (_cvOut->isValidReal(convValSmeared)) {
theEvent = *_modelVars ;
theEvent = *_pdfVars ;
_cvOut->setVal(convValSmeared) ;
return ;
}
}
}
void RooConvGenContext::setProtoDataOrder(Int_t* lut)
{
RooAbsGenContext::setProtoDataOrder(lut) ;
_modelGen->setProtoDataOrder(lut) ;
_pdfGen->setProtoDataOrder(lut) ;
}
void RooConvGenContext::printMultiline(ostream &os, Int_t content, Bool_t verbose, TString indent) const
{
RooAbsGenContext::printMultiline(os,content,verbose,indent) ;
os << indent << "--- RooConvGenContext ---" << endl ;
os << indent << "List of component generators" << endl ;
TString indent2(indent) ;
indent2.Append(" ") ;
_modelGen->printMultiline(os,content,verbose,indent2);
_pdfGen->printMultiline(os,content,verbose,indent2);
}
RooConvGenContext.cxx:100 RooConvGenContext.cxx:101 RooConvGenContext.cxx:102 RooConvGenContext.cxx:103 RooConvGenContext.cxx:104 RooConvGenContext.cxx:105 RooConvGenContext.cxx:106 RooConvGenContext.cxx:107 RooConvGenContext.cxx:108 RooConvGenContext.cxx:109 RooConvGenContext.cxx:110 RooConvGenContext.cxx:111 RooConvGenContext.cxx:112 RooConvGenContext.cxx:113 RooConvGenContext.cxx:114 RooConvGenContext.cxx:115 RooConvGenContext.cxx:116 RooConvGenContext.cxx:117 RooConvGenContext.cxx:118 RooConvGenContext.cxx:119 RooConvGenContext.cxx:120 RooConvGenContext.cxx:121 RooConvGenContext.cxx:122 RooConvGenContext.cxx:123 RooConvGenContext.cxx:124 RooConvGenContext.cxx:125 RooConvGenContext.cxx:126 RooConvGenContext.cxx:127 RooConvGenContext.cxx:128 RooConvGenContext.cxx:129 RooConvGenContext.cxx:130 RooConvGenContext.cxx:131 RooConvGenContext.cxx:132 RooConvGenContext.cxx:133 RooConvGenContext.cxx:134 RooConvGenContext.cxx:135 RooConvGenContext.cxx:136 RooConvGenContext.cxx:137 RooConvGenContext.cxx:138 RooConvGenContext.cxx:139 RooConvGenContext.cxx:140 RooConvGenContext.cxx:141 RooConvGenContext.cxx:142 RooConvGenContext.cxx:143 RooConvGenContext.cxx:144 RooConvGenContext.cxx:145 RooConvGenContext.cxx:146 RooConvGenContext.cxx:147 RooConvGenContext.cxx:148 RooConvGenContext.cxx:149 RooConvGenContext.cxx:150 RooConvGenContext.cxx:151 RooConvGenContext.cxx:152 RooConvGenContext.cxx:153 RooConvGenContext.cxx:154 RooConvGenContext.cxx:155 RooConvGenContext.cxx:156 RooConvGenContext.cxx:157 RooConvGenContext.cxx:158 RooConvGenContext.cxx:159 RooConvGenContext.cxx:160 RooConvGenContext.cxx:161 RooConvGenContext.cxx:162 RooConvGenContext.cxx:163 RooConvGenContext.cxx:164 RooConvGenContext.cxx:165 RooConvGenContext.cxx:166 RooConvGenContext.cxx:167 RooConvGenContext.cxx:168 RooConvGenContext.cxx:169 RooConvGenContext.cxx:170 RooConvGenContext.cxx:171 RooConvGenContext.cxx:172 RooConvGenContext.cxx:173 RooConvGenContext.cxx:174 RooConvGenContext.cxx:175 RooConvGenContext.cxx:176 RooConvGenContext.cxx:177 RooConvGenContext.cxx:178 RooConvGenContext.cxx:179 RooConvGenContext.cxx:180 RooConvGenContext.cxx:181 RooConvGenContext.cxx:182 RooConvGenContext.cxx:183 RooConvGenContext.cxx:184 RooConvGenContext.cxx:185 RooConvGenContext.cxx:186 RooConvGenContext.cxx:187 RooConvGenContext.cxx:188 RooConvGenContext.cxx:189 RooConvGenContext.cxx:190 RooConvGenContext.cxx:191 RooConvGenContext.cxx:192 RooConvGenContext.cxx:193 RooConvGenContext.cxx:194 RooConvGenContext.cxx:195 RooConvGenContext.cxx:196 RooConvGenContext.cxx:197 RooConvGenContext.cxx:198 RooConvGenContext.cxx:199 RooConvGenContext.cxx:200 RooConvGenContext.cxx:201 RooConvGenContext.cxx:202 RooConvGenContext.cxx:203 RooConvGenContext.cxx:204 RooConvGenContext.cxx:205 RooConvGenContext.cxx:206 RooConvGenContext.cxx:207 RooConvGenContext.cxx:208 RooConvGenContext.cxx:209 RooConvGenContext.cxx:210 RooConvGenContext.cxx:211 RooConvGenContext.cxx:212 RooConvGenContext.cxx:213 RooConvGenContext.cxx:214 RooConvGenContext.cxx:215 RooConvGenContext.cxx:216 RooConvGenContext.cxx:217 RooConvGenContext.cxx:218 RooConvGenContext.cxx:219 RooConvGenContext.cxx:220 RooConvGenContext.cxx:221 RooConvGenContext.cxx:222 RooConvGenContext.cxx:223 RooConvGenContext.cxx:224 RooConvGenContext.cxx:225 RooConvGenContext.cxx:226 RooConvGenContext.cxx:227 RooConvGenContext.cxx:228 RooConvGenContext.cxx:229 RooConvGenContext.cxx:230 RooConvGenContext.cxx:231 RooConvGenContext.cxx:232 RooConvGenContext.cxx:233 RooConvGenContext.cxx:234 RooConvGenContext.cxx:235 RooConvGenContext.cxx:236 RooConvGenContext.cxx:237 RooConvGenContext.cxx:238 RooConvGenContext.cxx:239 RooConvGenContext.cxx:240 RooConvGenContext.cxx:241 RooConvGenContext.cxx:242 RooConvGenContext.cxx:243 RooConvGenContext.cxx:244 RooConvGenContext.cxx:245 RooConvGenContext.cxx:246 RooConvGenContext.cxx:247 RooConvGenContext.cxx:248 RooConvGenContext.cxx:249 RooConvGenContext.cxx:250 RooConvGenContext.cxx:251 RooConvGenContext.cxx:252 RooConvGenContext.cxx:253 RooConvGenContext.cxx:254 RooConvGenContext.cxx:255 RooConvGenContext.cxx:256 RooConvGenContext.cxx:257 RooConvGenContext.cxx:258 RooConvGenContext.cxx:259 RooConvGenContext.cxx:260 RooConvGenContext.cxx:261 RooConvGenContext.cxx:262 RooConvGenContext.cxx:263 RooConvGenContext.cxx:264 RooConvGenContext.cxx:265 RooConvGenContext.cxx:266 RooConvGenContext.cxx:267 RooConvGenContext.cxx:268 RooConvGenContext.cxx:269 RooConvGenContext.cxx:270 RooConvGenContext.cxx:271 RooConvGenContext.cxx:272 RooConvGenContext.cxx:273 RooConvGenContext.cxx:274 RooConvGenContext.cxx:275 RooConvGenContext.cxx:276 RooConvGenContext.cxx:277 RooConvGenContext.cxx:278 RooConvGenContext.cxx:279 RooConvGenContext.cxx:280 RooConvGenContext.cxx:281 RooConvGenContext.cxx:282 RooConvGenContext.cxx:283 RooConvGenContext.cxx:284 RooConvGenContext.cxx:285 RooConvGenContext.cxx:286 RooConvGenContext.cxx:287 RooConvGenContext.cxx:288 RooConvGenContext.cxx:289 RooConvGenContext.cxx:290 RooConvGenContext.cxx:291 RooConvGenContext.cxx:292 RooConvGenContext.cxx:293 RooConvGenContext.cxx:294 RooConvGenContext.cxx:295 RooConvGenContext.cxx:296 RooConvGenContext.cxx:297 RooConvGenContext.cxx:298 RooConvGenContext.cxx:299 RooConvGenContext.cxx:300 RooConvGenContext.cxx:301 RooConvGenContext.cxx:302 RooConvGenContext.cxx:303 RooConvGenContext.cxx:304 RooConvGenContext.cxx:305 RooConvGenContext.cxx:306 RooConvGenContext.cxx:307 RooConvGenContext.cxx:308 RooConvGenContext.cxx:309 RooConvGenContext.cxx:310 RooConvGenContext.cxx:311 RooConvGenContext.cxx:312 RooConvGenContext.cxx:313 RooConvGenContext.cxx:314 RooConvGenContext.cxx:315 RooConvGenContext.cxx:316 RooConvGenContext.cxx:317 RooConvGenContext.cxx:318 RooConvGenContext.cxx:319 RooConvGenContext.cxx:320 RooConvGenContext.cxx:321 RooConvGenContext.cxx:322 RooConvGenContext.cxx:323 RooConvGenContext.cxx:324 RooConvGenContext.cxx:325 RooConvGenContext.cxx:326 RooConvGenContext.cxx:327 RooConvGenContext.cxx:328 RooConvGenContext.cxx:329 RooConvGenContext.cxx:330 RooConvGenContext.cxx:331