00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 #include "RooFit.h"
00063
00064 #include "TClass.h"
00065 #include "TMath.h"
00066 #include "Riostream.h"
00067 #include "RooResolutionModel.h"
00068 #include "RooMsgService.h"
00069 #include "RooSentinel.h"
00070
00071 ClassImp(RooResolutionModel)
00072 ;
00073
00074 RooFormulaVar* RooResolutionModel::_identity = 0;
00075
00076
00077
00078
00079 void RooResolutionModel::cleanup()
00080 {
00081
00082 delete _identity ;
00083 _identity = 0 ;
00084 }
00085
00086
00087
00088 RooResolutionModel::RooResolutionModel(const char *name, const char *title, RooRealVar& _x) :
00089 RooAbsPdf(name,title),
00090 x("x","Dependent or convolution variable",this,_x),
00091 _basisCode(0), _basis(0),
00092 _ownBasis(kFALSE)
00093 {
00094
00095
00096 if (!_identity) {
00097 _identity = identity() ;
00098 }
00099 }
00100
00101
00102
00103
00104 RooResolutionModel::RooResolutionModel(const RooResolutionModel& other, const char* name) :
00105 RooAbsPdf(other,name),
00106 x("x",this,other.x),
00107 _basisCode(other._basisCode), _basis(0),
00108 _ownBasis(kFALSE)
00109 {
00110
00111
00112 if (other._basis) {
00113 _basis = (RooFormulaVar*) other._basis->Clone() ;
00114 _ownBasis = kTRUE ;
00115
00116 }
00117
00118 if (_basis) {
00119 TIterator* bsIter = _basis->serverIterator() ;
00120 RooAbsArg* basisServer ;
00121 while((basisServer = (RooAbsArg*)bsIter->Next())) {
00122 addServer(*basisServer,kTRUE,kFALSE) ;
00123 }
00124 delete bsIter ;
00125 }
00126 }
00127
00128
00129
00130
00131 RooResolutionModel::~RooResolutionModel()
00132 {
00133
00134
00135 if (_ownBasis && _basis) {
00136 delete _basis ;
00137 }
00138 }
00139
00140
00141
00142
00143 RooFormulaVar* RooResolutionModel::identity()
00144 {
00145
00146
00147 if (!_identity) {
00148 _identity = new RooFormulaVar("identity","1",RooArgSet("")) ;
00149 RooSentinel::activate() ;
00150 }
00151
00152 return _identity ;
00153 }
00154
00155
00156
00157
00158 RooResolutionModel* RooResolutionModel::convolution(RooFormulaVar* inBasis, RooAbsArg* owner) const
00159 {
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 if (inBasis->getParameter(0) != x.absArg()) {
00171 coutE(InputArguments) << "RooResolutionModel::convolution(" << GetName() << "," << this
00172 << ") convolution parameter of basis function and PDF don't match" << endl
00173 << "basis->findServer(0) = " << inBasis->findServer(0) << endl
00174 << "x.absArg() = " << x.absArg() << endl ;
00175 return 0 ;
00176 }
00177
00178 if (basisCode(inBasis->GetTitle())==0) {
00179 coutE(InputArguments) << "RooResolutionModel::convolution(" << GetName() << "," << this
00180 << ") basis function '" << inBasis->GetTitle() << "' is not supported." << endl ;
00181 return 0 ;
00182 }
00183
00184 TString newName(GetName()) ;
00185 newName.Append("_conv_") ;
00186 newName.Append(inBasis->GetName()) ;
00187 newName.Append("_[") ;
00188 newName.Append(owner->GetName()) ;
00189 newName.Append("]") ;
00190
00191 RooResolutionModel* conv = (RooResolutionModel*) clone(newName) ;
00192
00193 TString newTitle(conv->GetTitle()) ;
00194 newTitle.Append(" convoluted with basis function ") ;
00195 newTitle.Append(inBasis->GetName()) ;
00196 conv->SetTitle(newTitle.Data()) ;
00197
00198 conv->changeBasis(inBasis) ;
00199
00200 return conv ;
00201 }
00202
00203
00204
00205
00206 void RooResolutionModel::changeBasis(RooFormulaVar* inBasis)
00207 {
00208
00209
00210
00211
00212 if (_basis) {
00213 TIterator* bsIter = _basis->serverIterator() ;
00214 RooAbsArg* basisServer ;
00215 while((basisServer = (RooAbsArg*)bsIter->Next())) {
00216 removeServer(*basisServer) ;
00217 }
00218 delete bsIter ;
00219
00220 if (_ownBasis) {
00221 delete _basis ;
00222 }
00223 }
00224 _ownBasis = kFALSE ;
00225
00226
00227 _basis = inBasis ;
00228 if (_basis) {
00229 TIterator* bsIter = _basis->serverIterator() ;
00230 RooAbsArg* basisServer ;
00231 while((basisServer = (RooAbsArg*)bsIter->Next())) {
00232 addServer(*basisServer,kTRUE,kFALSE) ;
00233 }
00234 delete bsIter ;
00235 }
00236
00237 _basisCode = inBasis?basisCode(inBasis->GetTitle()):0 ;
00238 }
00239
00240
00241
00242
00243 const RooRealVar& RooResolutionModel::basisConvVar() const
00244 {
00245
00246
00247
00248
00249 TIterator* sIter = basis().serverIterator() ;
00250 RooRealVar* var = (RooRealVar*) sIter->Next() ;
00251 delete sIter ;
00252
00253 return *var ;
00254 }
00255
00256
00257
00258
00259 RooRealVar& RooResolutionModel::convVar() const
00260 {
00261
00262
00263 return (RooRealVar&) x.arg() ;
00264 }
00265
00266
00267
00268
00269 Double_t RooResolutionModel::getVal(const RooArgSet* nset) const
00270 {
00271
00272
00273
00274
00275 if (!_basis) return RooAbsPdf::getVal(nset) ;
00276
00277
00278 if (isValueDirty()) {
00279 _value = evaluate() ;
00280
00281
00282 if (_verboseDirty) cxcoutD(Tracing) << "RooResolutionModel(" << GetName() << ") value = " << _value << endl ;
00283
00284 clearValueDirty() ;
00285 clearShapeDirty() ;
00286 }
00287
00288 return _value ;
00289 }
00290
00291
00292
00293
00294 Bool_t RooResolutionModel::redirectServersHook(const RooAbsCollection& newServerList, Bool_t mustReplaceAll, Bool_t nameChange, Bool_t )
00295 {
00296
00297
00298
00299 if (!_basis) {
00300 _norm = 0 ;
00301 return kFALSE ;
00302 }
00303
00304 RooFormulaVar* newBasis = (RooFormulaVar*) newServerList.find(_basis->GetName()) ;
00305 if (newBasis) {
00306
00307 if (_ownBasis) {
00308 delete _basis ;
00309 }
00310
00311 _basis = newBasis ;
00312 _ownBasis = kFALSE ;
00313 }
00314
00315 _basis->redirectServers(newServerList,mustReplaceAll,nameChange) ;
00316
00317 return (mustReplaceAll && !newBasis) ;
00318 }
00319
00320
00321
00322
00323 Bool_t RooResolutionModel::traceEvalHook(Double_t value) const
00324 {
00325
00326
00327
00328 return isnan(value) ;
00329 }
00330
00331
00332
00333
00334 void RooResolutionModel::normLeafServerList(RooArgSet& list) const
00335 {
00336
00337
00338 _norm->leafNodeServerList(&list) ;
00339 }
00340
00341
00342
00343
00344 Double_t RooResolutionModel::getNorm(const RooArgSet* nset) const
00345 {
00346
00347
00348 if (!nset) {
00349 return getVal() ;
00350 }
00351
00352 syncNormalization(nset,kFALSE) ;
00353 if (_verboseEval>1) cxcoutD(Tracing) << IsA()->GetName() << "::getNorm(" << GetName()
00354 << "): norm(" << _norm << ") = " << _norm->getVal() << endl ;
00355
00356 Double_t ret = _norm->getVal() ;
00357 return ret ;
00358 }
00359
00360
00361
00362
00363 void RooResolutionModel::printMultiline(ostream& os, Int_t content, Bool_t verbose, TString indent) const
00364 {
00365
00366
00367
00368
00369
00370
00371 RooAbsPdf::printMultiline(os,content,verbose,indent) ;
00372
00373 if(verbose) {
00374 os << indent << "--- RooResolutionModel ---" << endl;
00375 os << indent << "basis function = " ;
00376 if (_basis) {
00377 _basis->printStream(os,kName|kAddress|kTitle,kSingleLine,indent) ;
00378 } else {
00379 os << "<none>" << endl ;
00380 }
00381 }
00382 }
00383