00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __CINT__
00015 #include "RooGlobalFunc.h"
00016 #endif
00017 #include "RooRealVar.h"
00018 #include "RooDataSet.h"
00019 #include "RooGaussian.h"
00020 #include "TCanvas.h"
00021 #include "RooPlot.h"
00022 using namespace RooFit ;
00023
00024
00025
00026 class TestBasic101 : public RooFitTestUnit
00027 {
00028 public:
00029 TestBasic101(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Fitting,plotting & event generation of basic p.d.f",refFile,writeRef,verbose) {} ;
00030 Bool_t testCode() {
00031
00032
00033
00034
00035
00036 RooRealVar x("x","x",-10,10) ;
00037 RooRealVar mean("mean","mean of gaussian",1,-10,10) ;
00038 RooRealVar sigma("sigma","width of gaussian",1,0.1,10) ;
00039
00040
00041 RooGaussian gauss("gauss","gaussian PDF",x,mean,sigma) ;
00042
00043
00044 RooPlot* xframe = x.frame(Title("Gaussian p.d.f.")) ;
00045
00046
00047
00048
00049
00050
00051 gauss.plotOn(xframe) ;
00052
00053
00054 sigma.setVal(3) ;
00055
00056
00057 gauss.plotOn(xframe,LineColor(kRed),Name("another")) ;
00058
00059
00060
00061
00062
00063
00064 RooDataSet* data = gauss.generate(x,10000) ;
00065
00066
00067
00068 RooPlot* xframe2 = x.frame(Title("Gaussian p.d.f. with data")) ;
00069 data->plotOn(xframe2) ;
00070 gauss.plotOn(xframe2) ;
00071
00072
00073
00074
00075
00076
00077 gauss.fitTo(*data) ;
00078
00079
00080
00081 regPlot(xframe ,"rf101_plot1") ;
00082 regPlot(xframe2,"rf101_plot2") ;
00083
00084 delete data ;
00085
00086 return kTRUE ;
00087 }
00088 } ;
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 #ifndef __CINT__
00105 #include "RooGlobalFunc.h"
00106 #endif
00107 #include "RooRealVar.h"
00108 #include "RooDataSet.h"
00109 #include "RooDataHist.h"
00110 #include "RooGaussian.h"
00111 #include "TCanvas.h"
00112 #include "RooPlot.h"
00113 #include "TTree.h"
00114 #include "TH1D.h"
00115 #include "TRandom.h"
00116 using namespace RooFit ;
00117
00118
00119 class TestBasic102 : public RooFitTestUnit
00120 {
00121 public:
00122 TestBasic102(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Data import methods",refFile,writeRef,verbose) {} ;
00123
00124 TH1* makeTH1()
00125 {
00126
00127
00128 TH1D* hh = new TH1D("hh","hh",25,-10,10) ;
00129 for (int i=0 ; i<100 ; i++) {
00130 hh->Fill(gRandom->Gaus(0,3)) ;
00131 }
00132 return hh ;
00133 }
00134
00135
00136 TTree* makeTTree()
00137 {
00138
00139
00140 TTree* tree = new TTree("tree","tree") ;
00141 Double_t* px = new Double_t ;
00142 Double_t* py = new Double_t ;
00143 tree->Branch("x",px,"x/D") ;
00144 tree->Branch("y",py,"y/D") ;
00145 for (int i=0 ; i<100 ; i++) {
00146 *px = gRandom->Gaus(0,3) ;
00147 *py = gRandom->Uniform()*30 - 15 ;
00148 tree->Fill() ;
00149 }
00150
00151
00152
00153
00154 return tree ;
00155 }
00156
00157 Bool_t testCode() {
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 TH1* hh = makeTH1() ;
00168
00169
00170 RooRealVar x("x","x",-10,10) ;
00171
00172
00173 RooDataHist dh("dh","dh",x,Import(*hh)) ;
00174
00175
00176
00177
00178
00179
00180 RooPlot* frame = x.frame(Title("Imported TH1 with Poisson error bars")) ;
00181 dh.plotOn(frame) ;
00182
00183
00184 RooRealVar mean("mean","mean",0,-10,10) ;
00185 RooRealVar sigma("sigma","sigma",3,0.1,10) ;
00186 RooGaussian gauss("gauss","gauss",x,mean,sigma) ;
00187 gauss.fitTo(dh) ;
00188 gauss.plotOn(frame) ;
00189
00190
00191
00192
00193
00194
00195
00196 RooPlot* frame2 = x.frame(Title("Imported TH1 with internal errors")) ;
00197 dh.plotOn(frame2,DataError(RooAbsData::SumW2)) ;
00198 gauss.plotOn(frame2) ;
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 TTree* tree = makeTTree() ;
00217
00218
00219 RooRealVar y("y","y",-10,10) ;
00220
00221
00222
00223
00224
00225
00226
00227
00228 RooDataSet ds("ds","ds",RooArgSet(x,y),Import(*tree)) ;
00229
00230
00231
00232
00233
00234
00235 RooPlot* frame3 = y.frame(Title("Unbinned data shown in default frame binning")) ;
00236 ds.plotOn(frame3) ;
00237
00238
00239 RooPlot* frame4 = y.frame(Title("Unbinned data shown with custom binning")) ;
00240 ds.plotOn(frame4,Binning(20)) ;
00241
00242
00243 regPlot(frame ,"rf102_plot1") ;
00244 regPlot(frame2,"rf102_plot2") ;
00245 regPlot(frame3,"rf102_plot3") ;
00246 regPlot(frame4,"rf102_plot4") ;
00247
00248 delete hh ;
00249 delete tree ;
00250
00251 return kTRUE ;
00252 }
00253 } ;
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273 #ifndef __CINT__
00274 #include "RooGlobalFunc.h"
00275 #endif
00276 #include "RooRealVar.h"
00277 #include "RooDataSet.h"
00278 #include "RooGaussian.h"
00279 #include "TCanvas.h"
00280 #include "RooConstVar.h"
00281 #include "RooPlot.h"
00282 #include "RooFitResult.h"
00283 #include "RooGenericPdf.h"
00284
00285 using namespace RooFit ;
00286
00287
00288 class TestBasic103 : public RooFitTestUnit
00289 {
00290 public:
00291 TestBasic103(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Interpreted expression p.d.f.",refFile,writeRef,verbose) {} ;
00292 Bool_t testCode() {
00293
00294
00295
00296
00297
00298
00299 RooRealVar x("x","x",-20,20) ;
00300
00301
00302
00303
00304
00305
00306
00307 RooRealVar alpha("alpha","alpha",5,0.1,10) ;
00308 RooGenericPdf genpdf("genpdf","genpdf","(1+0.1*abs(x)+sin(sqrt(abs(x*alpha+0.1))))",RooArgSet(x,alpha)) ;
00309
00310
00311
00312
00313
00314
00315 RooDataSet* data = genpdf.generate(x,10000) ;
00316
00317
00318 genpdf.fitTo(*data) ;
00319
00320
00321 RooPlot* xframe = x.frame(Title("Interpreted expression pdf")) ;
00322 data->plotOn(xframe) ;
00323 genpdf.plotOn(xframe) ;
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338 RooRealVar mean2("mean2","mean^2",10,0,200) ;
00339 RooRealVar sigma("sigma","sigma",3,0.1,10) ;
00340
00341
00342 RooFormulaVar mean("mean","mean","sqrt(mean2)",mean2) ;
00343
00344
00345 RooGaussian g2("g2","h2",x,mean,sigma) ;
00346
00347
00348
00349
00350
00351
00352 RooGaussian g1("g1","g1",x,RooConst(10),RooConst(3)) ;
00353 RooDataSet* data2 = g1.generate(x,1000) ;
00354
00355
00356
00357
00358
00359
00360 RooFitResult* r = g2.fitTo(*data2,Save()) ;
00361
00362
00363 RooPlot* xframe2 = x.frame(Title("Tailored Gaussian pdf")) ;
00364 data2->plotOn(xframe2) ;
00365 g2.plotOn(xframe2) ;
00366
00367 regPlot(xframe,"rf103_plot1") ;
00368 regPlot(xframe2,"rf103_plot2") ;
00369 regResult(r,"rf103_fit1") ;
00370
00371 delete data ;
00372 delete data2 ;
00373
00374 return kTRUE ;
00375 }
00376 } ;
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388 #ifndef __CINT__
00389 #include "RooGlobalFunc.h"
00390 #endif
00391 #include "RooRealVar.h"
00392 #include "RooDataSet.h"
00393 #include "RooGaussian.h"
00394 #include "TCanvas.h"
00395 #include "RooPlot.h"
00396 #include "TMath.h"
00397 #include "TF1.h"
00398 #include "Math/DistFunc.h"
00399 #include "RooCFunction1Binding.h"
00400 #include "RooCFunction3Binding.h"
00401 #include "RooTFnBinding.h"
00402
00403 using namespace RooFit ;
00404
00405 class TestBasic105 : public RooFitTestUnit
00406 {
00407 public:
00408 TestBasic105(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("C++ function binding operator p.d.f",refFile,writeRef,verbose) {} ;
00409 Bool_t testCode() {
00410
00411
00412
00413
00414
00415 RooRealVar x("x","x",-3,3) ;
00416 RooAbsReal* erf = bindFunction("erf",TMath::Erf,x) ;
00417
00418
00419 RooPlot* frame1 = x.frame(Title("TMath::Erf bound as RooFit function")) ;
00420 erf->plotOn(frame1) ;
00421
00422
00423
00424
00425
00426
00427 RooRealVar x2("x2","x2",0,0.999) ;
00428 RooRealVar a("a","a",5,0,10) ;
00429 RooRealVar b("b","b",2,0,10) ;
00430 RooAbsPdf* beta = bindPdf("beta",ROOT::Math::beta_pdf,x2,a,b) ;
00431
00432
00433 RooDataSet* data = beta->generate(x2,10000) ;
00434 beta->fitTo(*data) ;
00435
00436
00437 RooPlot* frame2 = x2.frame(Title("ROOT::Math::Beta bound as RooFit pdf")) ;
00438 data->plotOn(frame2) ;
00439 beta->plotOn(frame2) ;
00440
00441
00442
00443
00444
00445
00446
00447 TF1 *fa1 = new TF1("fa1","sin(x)/x",0,10);
00448
00449
00450 RooRealVar x3("x3","x3",0.01,20) ;
00451
00452
00453 RooAbsReal* rfa1 = bindFunction(fa1,x3) ;
00454
00455
00456 RooPlot* frame3 = x3.frame(Title("TF1 bound as RooFit function")) ;
00457 rfa1->plotOn(frame3) ;
00458
00459
00460 regPlot(frame1,"rf105_plot1") ;
00461 regPlot(frame2,"rf105_plot2") ;
00462 regPlot(frame3,"rf105_plot3") ;
00463
00464 delete erf ;
00465 delete beta ;
00466 delete fa1 ;
00467 delete rfa1 ;
00468 delete data ;
00469
00470 return kTRUE ;
00471 }
00472 } ;
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484 #ifndef __CINT__
00485 #include "RooGlobalFunc.h"
00486 #endif
00487 #include "RooRealVar.h"
00488 #include "RooDataSet.h"
00489 #include "RooGaussModel.h"
00490 #include "RooDecay.h"
00491 #include "RooBMixDecay.h"
00492 #include "RooCategory.h"
00493 #include "RooBinning.h"
00494 #include "RooPlot.h"
00495 #include "TCanvas.h"
00496 #include "TH1.h"
00497 using namespace RooFit ;
00498
00499
00500 class TestBasic108 : public RooFitTestUnit
00501 {
00502 public:
00503 TestBasic108(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Non-standard binning in counting and asymmetry plots",refFile,writeRef,verbose) {} ;
00504 Bool_t testCode() {
00505
00506
00507
00508
00509
00510 RooRealVar dt("dt","dt",-20,20) ;
00511 RooRealVar dm("dm","dm",0.472) ;
00512 RooRealVar tau("tau","tau",1.547) ;
00513 RooRealVar w("w","mistag rate",0.1) ;
00514 RooRealVar dw("dw","delta mistag rate",0.) ;
00515
00516 RooCategory mixState("mixState","B0/B0bar mixing state") ;
00517 mixState.defineType("mixed",-1) ;
00518 mixState.defineType("unmixed",1) ;
00519 RooCategory tagFlav("tagFlav","Flavour of the tagged B0") ;
00520 tagFlav.defineType("B0",1) ;
00521 tagFlav.defineType("B0bar",-1) ;
00522
00523
00524 RooRealVar dterr("dterr","dterr",0.1,1.0) ;
00525 RooRealVar bias1("bias1","bias1",0) ;
00526 RooRealVar sigma1("sigma1","sigma1",0.1) ;
00527 RooGaussModel gm1("gm1","gauss model 1",dt,bias1,sigma1) ;
00528
00529
00530 RooBMixDecay bmix("bmix","decay",dt,mixState,tagFlav,tau,dm,w,dw,gm1,RooBMixDecay::DoubleSided) ;
00531
00532
00533
00534
00535
00536
00537 RooDataSet *data = bmix.generate(RooArgSet(dt,mixState,tagFlav),2000) ;
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547 RooBinning tbins(-15,15) ;
00548
00549
00550 tbins.addUniform(60,-15,0) ;
00551
00552
00553 tbins.addUniform(15,0,15) ;
00554
00555
00556 RooPlot* dtframe = dt.frame(Range(-15,15),Title("dt distribution with custom binning")) ;
00557 data->plotOn(dtframe,Binning(tbins)) ;
00558 bmix.plotOn(dtframe) ;
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570 RooBinning abins(-10,10) ;
00571
00572
00573 abins.addBoundary(0) ;
00574 abins.addBoundaryPair(1) ;
00575 abins.addBoundaryPair(2) ;
00576 abins.addBoundaryPair(3) ;
00577 abins.addBoundaryPair(4) ;
00578 abins.addBoundaryPair(6) ;
00579
00580
00581 RooPlot* aframe = dt.frame(Range(-10,10),Title("mixState asymmetry distribution with custom binning")) ;
00582
00583
00584 data->plotOn(aframe,Asymmetry(mixState),Binning(abins)) ;
00585
00586
00587 bmix.plotOn(aframe,Asymmetry(mixState)) ;
00588
00589
00590 aframe->SetMinimum(-1.1) ;
00591 aframe->SetMaximum(1.1) ;
00592
00593
00594
00595
00596 regPlot(dtframe,"rf108_plot1") ;
00597 regPlot(aframe,"rf108_plot2") ;
00598
00599 delete data ;
00600
00601 return kTRUE ;
00602 }
00603 } ;
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617 #ifndef __CINT__
00618 #include "RooGlobalFunc.h"
00619 #endif
00620 #include "RooRealVar.h"
00621 #include "RooDataSet.h"
00622 #include "RooGaussian.h"
00623 #include "TCanvas.h"
00624 #include "RooPlot.h"
00625 #include "RooHist.h"
00626 using namespace RooFit ;
00627
00628 class TestBasic109 : public RooFitTestUnit
00629 {
00630 public:
00631 TestBasic109(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Calculation of chi^2 and residuals in plots",refFile,writeRef,verbose) {} ;
00632 Bool_t testCode() {
00633
00634
00635
00636
00637
00638 RooRealVar x("x","x",-10,10) ;
00639
00640
00641 RooRealVar sigma("sigma","sigma",3,0.1,10) ;
00642 RooRealVar mean("mean","mean",0,-10,10) ;
00643 RooGaussian gauss("gauss","gauss",x,RooConst(0),sigma) ;
00644
00645
00646 RooDataSet* data = gauss.generate(x,10000) ;
00647
00648
00649 sigma=3.15 ;
00650
00651
00652
00653
00654
00655
00656 RooPlot* frame1 = x.frame(Title("Data with distorted Gaussian pdf"),Bins(40)) ;
00657 data->plotOn(frame1,DataError(RooAbsData::SumW2)) ;
00658 gauss.plotOn(frame1) ;
00659
00660
00661
00662
00663
00664
00665
00666
00667 regValue(frame1->chiSquare(),"rf109_chi2") ;
00668
00669
00670
00671
00672
00673
00674 RooHist* hresid = frame1->residHist() ;
00675
00676
00677 RooHist* hpull = frame1->pullHist() ;
00678
00679
00680 RooPlot* frame2 = x.frame(Title("Residual Distribution")) ;
00681 frame2->addPlotable(hresid,"P") ;
00682
00683
00684 RooPlot* frame3 = x.frame(Title("Pull Distribution")) ;
00685 frame3->addPlotable(hpull,"P") ;
00686
00687 regPlot(frame1,"rf109_plot1") ;
00688 regPlot(frame2,"rf109_plot2") ;
00689 regPlot(frame3,"rf109_plot3") ;
00690
00691 delete data ;
00692
00693
00694
00695 return kTRUE ;
00696 }
00697 } ;
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711 #ifndef __CINT__
00712 #include "RooGlobalFunc.h"
00713 #endif
00714 #include "RooRealVar.h"
00715 #include "RooGaussian.h"
00716 #include "RooAbsReal.h"
00717 #include "RooPlot.h"
00718 #include "TCanvas.h"
00719 using namespace RooFit ;
00720
00721 class TestBasic110 : public RooFitTestUnit
00722 {
00723 public:
00724 TestBasic110(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Normalization of p.d.f.s in 1D",refFile,writeRef,verbose) {} ;
00725 Bool_t testCode() {
00726
00727
00728
00729
00730
00731 RooRealVar x("x","x",-10,10) ;
00732
00733
00734 RooGaussian gx("gx","gx",x,RooConst(-2),RooConst(3)) ;
00735
00736
00737
00738
00739
00740
00741 regValue(gx.getVal(),"rf110_gx") ;
00742
00743
00744 RooArgSet nset(x) ;
00745
00746 regValue(gx.getVal(&nset),"rf110_gx_Norm[x]") ;
00747
00748
00749
00750 RooAbsReal* igx = gx.createIntegral(x) ;
00751 regValue(igx->getVal(),"rf110_gx_Int[x]") ;
00752
00753
00754
00755
00756
00757
00758 x.setRange("signal",-5,5) ;
00759
00760
00761
00762
00763 RooAbsReal* igx_sig = gx.createIntegral(x,NormSet(x),Range("signal")) ;
00764 regValue(igx_sig->getVal(),"rf110_gx_Int[x|signal]_Norm[x]") ;
00765
00766
00767
00768
00769
00770
00771
00772
00773 RooAbsReal* gx_cdf = gx.createCdf(x) ;
00774
00775
00776 RooPlot* frame = x.frame(Title("c.d.f of Gaussian p.d.f")) ;
00777 gx_cdf->plotOn(frame) ;
00778
00779
00780 regPlot(frame,"rf110_plot1") ;
00781
00782 delete igx ;
00783 delete igx_sig ;
00784 delete gx_cdf ;
00785
00786 return kTRUE ;
00787 }
00788 } ;
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802 #ifndef __CINT__
00803 #include "RooGlobalFunc.h"
00804 #endif
00805 #include "RooRealVar.h"
00806 #include "RooDataSet.h"
00807 #include "RooGaussian.h"
00808 #include "TCanvas.h"
00809 #include "RooPlot.h"
00810 #include "RooNumIntConfig.h"
00811 #include "RooLandau.h"
00812 #include "RooArgSet.h"
00813 #include <iomanip>
00814 using namespace RooFit ;
00815
00816 class TestBasic111 : public RooFitTestUnit
00817 {
00818 public:
00819 TestBasic111(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Numeric integration configuration",refFile,writeRef,verbose) {} ;
00820 Bool_t testCode() {
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836 RooAbsReal::defaultIntegratorConfig()->setEpsAbs(1e-6) ;
00837 RooAbsReal::defaultIntegratorConfig()->setEpsRel(1e-6) ;
00838
00839
00840
00841
00842
00843
00844 RooRealVar x("x","x",-10,10) ;
00845 RooLandau landau("landau","landau",x,RooConst(0),RooConst(0.1)) ;
00846
00847
00848
00849 RooAbsReal* intLandau = landau.createIntegral(x) ;
00850 Double_t val = intLandau->getVal() ;
00851 regValue(val,"rf111_val1") ;
00852
00853
00854
00855
00856
00857
00858
00859
00860 RooNumIntConfig customConfig(*RooAbsReal::defaultIntegratorConfig()) ;
00861 customConfig.method1D().setLabel("RooAdaptiveGaussKronrodIntegrator1D") ;
00862
00863
00864
00865 RooAbsReal* intLandau2 = landau.createIntegral(x,NumIntConfig(customConfig)) ;
00866 Double_t val2 = intLandau2->getVal() ;
00867 regValue(val2,"rf111_val2") ;
00868
00869
00870
00871
00872
00873
00874
00875 landau.setIntegratorConfig(customConfig) ;
00876
00877
00878
00879 RooAbsReal* intLandau3 = landau.createIntegral(x) ;
00880 Double_t val3 = intLandau3->getVal() ;
00881 regValue(val3,"rf111_val3") ;
00882
00883
00884 delete intLandau ;
00885 delete intLandau2 ;
00886 delete intLandau3 ;
00887
00888 return kTRUE ;
00889 }
00890 } ;
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904 #ifndef __CINT__
00905 #include "RooGlobalFunc.h"
00906 #endif
00907 #include "RooRealVar.h"
00908 #include "RooDataSet.h"
00909 #include "RooGaussian.h"
00910 #include "RooChebychev.h"
00911 #include "RooAddPdf.h"
00912 #include "TCanvas.h"
00913 #include "RooPlot.h"
00914 using namespace RooFit ;
00915
00916
00917 class TestBasic201 : public RooFitTestUnit
00918 {
00919 public:
00920 TestBasic201(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Addition operator p.d.f.",refFile,writeRef,verbose) {} ;
00921 Bool_t testCode() {
00922
00923
00924
00925
00926
00927 RooRealVar x("x","x",0,10) ;
00928
00929
00930 RooRealVar mean("mean","mean of gaussians",5) ;
00931 RooRealVar sigma1("sigma1","width of gaussians",0.5) ;
00932 RooRealVar sigma2("sigma2","width of gaussians",1) ;
00933
00934 RooGaussian sig1("sig1","Signal component 1",x,mean,sigma1) ;
00935 RooGaussian sig2("sig2","Signal component 2",x,mean,sigma2) ;
00936
00937
00938 RooRealVar a0("a0","a0",0.5,0.,1.) ;
00939 RooRealVar a1("a1","a1",-0.2,0.,1.) ;
00940 RooChebychev bkg("bkg","Background",x,RooArgSet(a0,a1)) ;
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952 RooRealVar sig1frac("sig1frac","fraction of component 1 in signal",0.8,0.,1.) ;
00953 RooAddPdf sig("sig","Signal",RooArgList(sig1,sig2),sig1frac) ;
00954
00955
00956
00957
00958
00959
00960 RooRealVar bkgfrac("bkgfrac","fraction of background",0.5,0.,1.) ;
00961 RooAddPdf model("model","g1+g2+a",RooArgList(bkg,sig),bkgfrac) ;
00962
00963
00964
00965
00966
00967
00968 RooDataSet *data = model.generate(x,1000) ;
00969
00970
00971 model.fitTo(*data) ;
00972
00973
00974 RooPlot* xframe = x.frame(Title("Example of composite pdf=(sig1+sig2)+bkg")) ;
00975 data->plotOn(xframe) ;
00976 model.plotOn(xframe) ;
00977
00978
00979 model.plotOn(xframe,Components(bkg),LineStyle(kDashed)) ;
00980
00981
00982 model.plotOn(xframe,Components(RooArgSet(bkg,sig2)),LineStyle(kDotted)) ;
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993 RooAddPdf model2("model","g1+g2+a",RooArgList(bkg,sig1,sig2),RooArgList(bkgfrac,sig1frac),kTRUE) ;
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005 model2.plotOn(xframe,LineColor(kRed),LineStyle(kDashed)) ;
01006 model2.plotOn(xframe,Components(RooArgSet(bkg,sig2)),LineColor(kRed),LineStyle(kDashed)) ;
01007
01008
01009 regPlot(xframe,"rf201_plot1") ;
01010
01011 delete data ;
01012 return kTRUE ;
01013
01014 }
01015
01016 } ;
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030 #ifndef __CINT__
01031 #include "RooGlobalFunc.h"
01032 #endif
01033 #include "RooRealVar.h"
01034 #include "RooDataSet.h"
01035 #include "RooGaussian.h"
01036 #include "RooChebychev.h"
01037 #include "RooAddPdf.h"
01038 #include "RooExtendPdf.h"
01039 #include "TCanvas.h"
01040 #include "RooPlot.h"
01041 using namespace RooFit ;
01042
01043
01044 class TestBasic202 : public RooFitTestUnit
01045 {
01046 public:
01047 TestBasic202(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Extended ML fits to addition operator p.d.f.s",refFile,writeRef,verbose) {} ;
01048 Bool_t testCode() {
01049
01050
01051
01052
01053
01054 RooRealVar x("x","x",0,10) ;
01055
01056
01057 RooRealVar mean("mean","mean of gaussians",5) ;
01058 RooRealVar sigma1("sigma1","width of gaussians",0.5) ;
01059 RooRealVar sigma2("sigma2","width of gaussians",1) ;
01060
01061 RooGaussian sig1("sig1","Signal component 1",x,mean,sigma1) ;
01062 RooGaussian sig2("sig2","Signal component 2",x,mean,sigma2) ;
01063
01064
01065 RooRealVar a0("a0","a0",0.5,0.,1.) ;
01066 RooRealVar a1("a1","a1",-0.2,0.,1.) ;
01067 RooChebychev bkg("bkg","Background",x,RooArgSet(a0,a1)) ;
01068
01069
01070 RooRealVar sig1frac("sig1frac","fraction of component 1 in signal",0.8,0.,1.) ;
01071 RooAddPdf sig("sig","Signal",RooArgList(sig1,sig2),sig1frac) ;
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082 RooRealVar nsig("nsig","number of signal events",500,0.,10000) ;
01083 RooRealVar nbkg("nbkg","number of background events",500,0,10000) ;
01084 RooAddPdf model("model","(g1+g2)+a",RooArgList(bkg,sig),RooArgList(nbkg,nsig)) ;
01085
01086
01087
01088
01089
01090
01091
01092
01093 RooDataSet *data = model.generate(x) ;
01094
01095
01096 model.fitTo(*data) ;
01097
01098
01099
01100 RooPlot* xframe = x.frame(Title("extended ML fit example")) ;
01101 data->plotOn(xframe) ;
01102 model.plotOn(xframe,Normalization(1.0,RooAbsReal::RelativeExpected)) ;
01103
01104
01105 model.plotOn(xframe,Components(bkg),LineStyle(kDashed),Normalization(1.0,RooAbsReal::RelativeExpected)) ;
01106
01107
01108 model.plotOn(xframe,Components(RooArgSet(bkg,sig2)),LineStyle(kDotted),Normalization(1.0,RooAbsReal::RelativeExpected)) ;
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119 RooExtendPdf esig("esig","extended signal p.d.f",sig,nsig) ;
01120 RooExtendPdf ebkg("ebkg","extended background p.d.f",bkg,nbkg) ;
01121
01122
01123
01124
01125
01126
01127 RooAddPdf model2("model2","(g1+g2)+a",RooArgList(ebkg,esig)) ;
01128
01129
01130 regPlot(xframe,"rf202_plot1") ;
01131
01132 delete data ;
01133 return kTRUE ;
01134
01135 }
01136
01137 } ;
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149 #ifndef __CINT__
01150 #include "RooGlobalFunc.h"
01151 #endif
01152 #include "RooRealVar.h"
01153 #include "RooDataSet.h"
01154 #include "RooGaussian.h"
01155 #include "RooPolynomial.h"
01156 #include "RooAddPdf.h"
01157 #include "RooFitResult.h"
01158 #include "RooPlot.h"
01159 #include "TCanvas.h"
01160 #include "TH1.h"
01161 using namespace RooFit ;
01162
01163
01164 class TestBasic203 : public RooFitTestUnit
01165 {
01166 public:
01167 TestBasic203(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Basic fitting and plotting in ranges",refFile,writeRef,verbose) {} ;
01168 Bool_t testCode() {
01169
01170
01171
01172
01173
01174 RooRealVar x("x","x",-10,10) ;
01175
01176
01177 RooRealVar mx("mx","mx",0,-10,10) ;
01178 RooGaussian gx("gx","gx",x,mx,RooConst(1)) ;
01179
01180
01181 RooPolynomial px("px","px",x) ;
01182
01183
01184 RooRealVar f("f","f",0.,1.) ;
01185 RooAddPdf model("model","model",RooArgList(gx,px),f) ;
01186
01187
01188 RooDataSet* modelData = model.generate(x,10000) ;
01189
01190
01191
01192
01193
01194 RooFitResult* r_full = model.fitTo(*modelData,Save(kTRUE)) ;
01195
01196
01197
01198
01199
01200
01201 x.setRange("signal",-3,3) ;
01202
01203
01204 RooFitResult* r_sig = model.fitTo(*modelData,Save(kTRUE),Range("signal")) ;
01205
01206
01207
01208
01209
01210
01211 RooPlot* frame = x.frame(Title("Fitting a sub range")) ;
01212 modelData->plotOn(frame) ;
01213 model.plotOn(frame,Range("Full"),LineStyle(kDashed),LineColor(kRed)) ;
01214 model.plotOn(frame) ;
01215
01216 regPlot(frame,"rf203_plot") ;
01217 regResult(r_full,"rf203_r_full") ;
01218 regResult(r_sig,"rf203_r_sig") ;
01219
01220 delete modelData ;
01221 return kTRUE;
01222 }
01223 } ;
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237 #ifndef __CINT__
01238 #include "RooGlobalFunc.h"
01239 #endif
01240 #include "RooRealVar.h"
01241 #include "RooDataSet.h"
01242 #include "RooGaussian.h"
01243 #include "RooChebychev.h"
01244 #include "RooAddPdf.h"
01245 #include "RooExtendPdf.h"
01246 #include "RooFitResult.h"
01247 #include "TCanvas.h"
01248 #include "RooPlot.h"
01249 using namespace RooFit ;
01250
01251
01252 class TestBasic204 : public RooFitTestUnit
01253 {
01254 public:
01255 TestBasic204(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Extended ML fit in sub range",refFile,writeRef,verbose) {} ;
01256 Bool_t testCode() {
01257
01258
01259
01260
01261
01262 RooRealVar x("x","x",0,10) ;
01263
01264
01265 RooRealVar mean("mean","mean of gaussians",5) ;
01266 RooRealVar sigma1("sigma1","width of gaussians",0.5) ;
01267 RooRealVar sigma2("sigma2","width of gaussians",1) ;
01268
01269 RooGaussian sig1("sig1","Signal component 1",x,mean,sigma1) ;
01270 RooGaussian sig2("sig2","Signal component 2",x,mean,sigma2) ;
01271
01272
01273 RooRealVar a0("a0","a0",0.5,0.,1.) ;
01274 RooRealVar a1("a1","a1",-0.2,0.,1.) ;
01275 RooChebychev bkg("bkg","Background",x,RooArgSet(a0,a1)) ;
01276
01277
01278 RooRealVar sig1frac("sig1frac","fraction of component 1 in signal",0.8,0.,1.) ;
01279 RooAddPdf sig("sig","Signal",RooArgList(sig1,sig2),sig1frac) ;
01280
01281
01282
01283
01284
01285
01286 x.setRange("signalRange",4,6) ;
01287
01288
01289 RooRealVar nsig("nsig","number of signal events in signalRange",500,0.,10000) ;
01290 RooRealVar nbkg("nbkg","number of background events in signalRange",500,0,10000) ;
01291 RooExtendPdf esig("esig","extended signal p.d.f",sig,nsig,"signalRange") ;
01292 RooExtendPdf ebkg("ebkg","extended background p.d.f",bkg,nbkg,"signalRange") ;
01293
01294
01295
01296
01297
01298
01299 RooAddPdf model("model","(g1+g2)+a",RooArgList(ebkg,esig)) ;
01300
01301
01302
01303
01304
01305
01306 RooDataSet *data = model.generate(x,1000) ;
01307
01308
01309
01310 RooFitResult* r = model.fitTo(*data,Extended(kTRUE),Save()) ;
01311
01312
01313 regResult(r,"rf204_result") ;
01314
01315 delete data ;
01316 return kTRUE ;
01317 }
01318 } ;
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331 #ifndef __CINT__
01332 #include "RooGlobalFunc.h"
01333 #endif
01334 #include "RooRealVar.h"
01335 #include "RooDataSet.h"
01336 #include "RooGaussian.h"
01337 #include "RooAddPdf.h"
01338 #include "RooChebychev.h"
01339 #include "RooExponential.h"
01340 #include "TCanvas.h"
01341 #include "RooPlot.h"
01342 using namespace RooFit ;
01343
01344
01345 class TestBasic205 : public RooFitTestUnit
01346 {
01347 public:
01348 TestBasic205(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Component plotting variations",refFile,writeRef,verbose) {} ;
01349 Bool_t testCode() {
01350
01351
01352
01353
01354
01355 RooRealVar x("x","x",0,10) ;
01356
01357
01358 RooRealVar mean("mean","mean of gaussians",5) ;
01359 RooRealVar sigma1("sigma1","width of gaussians",0.5) ;
01360 RooRealVar sigma2("sigma2","width of gaussians",1) ;
01361 RooGaussian sig1("sig1","Signal component 1",x,mean,sigma1) ;
01362 RooGaussian sig2("sig2","Signal component 2",x,mean,sigma2) ;
01363
01364
01365 RooRealVar sig1frac("sig1frac","fraction of component 1 in signal",0.8,0.,1.) ;
01366 RooAddPdf sig("sig","Signal",RooArgList(sig1,sig2),sig1frac) ;
01367
01368
01369 RooRealVar a0("a0","a0",0.5,0.,1.) ;
01370 RooRealVar a1("a1","a1",-0.2,0.,1.) ;
01371 RooChebychev bkg1("bkg1","Background 1",x,RooArgSet(a0,a1)) ;
01372
01373
01374 RooRealVar alpha("alpha","alpha",-1) ;
01375 RooExponential bkg2("bkg2","Background 2",x,alpha) ;
01376
01377
01378 RooRealVar bkg1frac("sig1frac","fraction of component 1 in background",0.2,0.,1.) ;
01379 RooAddPdf bkg("bkg","Signal",RooArgList(bkg1,bkg2),sig1frac) ;
01380
01381
01382 RooRealVar bkgfrac("bkgfrac","fraction of background",0.5,0.,1.) ;
01383 RooAddPdf model("model","g1+g2+a",RooArgList(bkg,sig),bkgfrac) ;
01384
01385
01386
01387
01388
01389
01390
01391 RooDataSet *data = model.generate(x,1000) ;
01392
01393
01394 RooPlot* xframe = x.frame(Title("Component plotting of pdf=(sig1+sig2)+(bkg1+bkg2)")) ;
01395 data->plotOn(xframe) ;
01396 model.plotOn(xframe) ;
01397
01398
01399 RooPlot* xframe2 = x.frame(Title("Component plotting of pdf=(sig1+sig2)+(bkg1+bkg2)"),Name("xframe2")) ;
01400
01401
01402
01403
01404
01405
01406 model.plotOn(xframe,Components(bkg),LineColor(kRed)) ;
01407
01408
01409 model.plotOn(xframe,Components(bkg2),LineStyle(kDashed),LineColor(kRed)) ;
01410
01411
01412
01413
01414 model.plotOn(xframe,Components(RooArgSet(bkg,sig2)),LineStyle(kDotted)) ;
01415
01416
01417
01418
01419
01420
01421
01422 model.plotOn(xframe2,Components("bkg"),LineColor(kCyan)) ;
01423
01424
01425 model.plotOn(xframe2,Components("bkg1,sig2"),LineStyle(kDotted),LineColor(kCyan)) ;
01426
01427
01428 model.plotOn(xframe2,Components("sig*"),LineStyle(kDashed),LineColor(kCyan)) ;
01429
01430
01431 model.plotOn(xframe2,Components("bkg1,sig*"),LineStyle(kDashed),LineColor(kYellow),Invisible()) ;
01432
01433
01434 regPlot(xframe,"rf205_plot1") ;
01435 regPlot(xframe2,"rf205_plot2") ;
01436
01437 delete data ;
01438 return kTRUE ;
01439
01440 }
01441
01442 } ;
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457 #ifndef __CINT__
01458 #include "RooGlobalFunc.h"
01459 #endif
01460 #include "RooRealVar.h"
01461 #include "RooDataSet.h"
01462 #include "RooGaussian.h"
01463 #include "RooLandau.h"
01464 #include "RooFFTConvPdf.h"
01465 #include "RooPlot.h"
01466 #include "TCanvas.h"
01467 #include "TH1.h"
01468 #include "TPluginManager.h"
01469 #include "TROOT.h"
01470
01471 using namespace RooFit ;
01472
01473
01474
01475 class TestBasic208 : public RooFitTestUnit
01476 {
01477 public:
01478 TestBasic208(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("FFT Convolution operator p.d.f.",refFile,writeRef,verbose) {} ;
01479
01480 Bool_t isTestAvailable() {
01481
01482 TPluginHandler *h;
01483 if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualFFT"))) {
01484 if (h->LoadPlugin() == -1) {
01485 gROOT->ProcessLine("new TNamed ;") ;
01486 return kFALSE;
01487 } else {
01488 return kTRUE ;
01489 }
01490 }
01491 return kFALSE ;
01492 }
01493
01494 Double_t ctol() { return 5e-3 ; }
01495
01496 Bool_t testCode() {
01497
01498
01499
01500
01501
01502 RooRealVar t("t","t",-10,30) ;
01503
01504
01505 RooRealVar ml("ml","mean landau",5.,-20,20) ;
01506 RooRealVar sl("sl","sigma landau",1,0.1,10) ;
01507 RooLandau landau("lx","lx",t,ml,sl) ;
01508
01509
01510 RooRealVar mg("mg","mg",0) ;
01511 RooRealVar sg("sg","sg",2,0.1,10) ;
01512 RooGaussian gauss("gauss","gauss",t,mg,sg) ;
01513
01514
01515
01516
01517
01518
01519 t.setBins(10000,"cache") ;
01520
01521
01522 RooFFTConvPdf lxg("lxg","landau (X) gauss",t,landau,gauss) ;
01523
01524
01525
01526
01527
01528
01529 RooDataSet* data = lxg.generate(t,10000) ;
01530
01531
01532 lxg.fitTo(*data) ;
01533
01534
01535 RooPlot* frame = t.frame(Title("landau (x) gauss convolution")) ;
01536 data->plotOn(frame) ;
01537 lxg.plotOn(frame) ;
01538 landau.plotOn(frame,LineStyle(kDashed)) ;
01539
01540 regPlot(frame,"rf208_plot1") ;
01541
01542 delete data ;
01543 return kTRUE ;
01544
01545 }
01546 } ;
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567 #ifndef __CINT__
01568 #include "RooGlobalFunc.h"
01569 #endif
01570 #include "RooRealVar.h"
01571 #include "RooDataSet.h"
01572 #include "RooGaussModel.h"
01573 #include "RooAddModel.h"
01574 #include "RooTruthModel.h"
01575 #include "RooDecay.h"
01576 #include "RooPlot.h"
01577 #include "TCanvas.h"
01578 #include "TH1.h"
01579 using namespace RooFit ;
01580
01581
01582
01583 class TestBasic209 : public RooFitTestUnit
01584 {
01585 public:
01586 TestBasic209(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Analytical convolution operator",refFile,writeRef,verbose) {} ;
01587 Bool_t testCode() {
01588
01589
01590
01591
01592
01593 RooRealVar dt("dt","dt",-10,10) ;
01594 RooRealVar tau("tau","tau",1.548) ;
01595
01596
01597 RooTruthModel tm("tm","truth model",dt) ;
01598
01599
01600 RooDecay decay_tm("decay_tm","decay",dt,tau,tm,RooDecay::DoubleSided) ;
01601
01602
01603 RooPlot* frame = dt.frame(Title("Bdecay (x) resolution")) ;
01604 decay_tm.plotOn(frame,LineStyle(kDashed)) ;
01605
01606
01607
01608
01609
01610
01611 RooRealVar bias1("bias1","bias1",0) ;
01612 RooRealVar sigma1("sigma1","sigma1",1) ;
01613 RooGaussModel gm1("gm1","gauss model 1",dt,bias1,sigma1) ;
01614
01615
01616 RooDecay decay_gm1("decay_gm1","decay",dt,tau,gm1,RooDecay::DoubleSided) ;
01617
01618
01619 decay_gm1.plotOn(frame) ;
01620
01621
01622
01623
01624
01625
01626 RooRealVar bias2("bias2","bias2",0) ;
01627 RooRealVar sigma2("sigma2","sigma2",5) ;
01628 RooGaussModel gm2("gm2","gauss model 2",dt,bias2,sigma2) ;
01629
01630
01631 RooRealVar gm1frac("gm1frac","fraction of gm1",0.5) ;
01632 RooAddModel gmsum("gmsum","sum of gm1 and gm2",RooArgList(gm1,gm2),gm1frac) ;
01633
01634
01635 RooDecay decay_gmsum("decay_gmsum","decay",dt,tau,gmsum,RooDecay::DoubleSided) ;
01636
01637
01638 decay_gmsum.plotOn(frame,LineColor(kRed)) ;
01639
01640 regPlot(frame,"rf209_plot1") ;
01641
01642 return kTRUE ;
01643
01644 }
01645 } ;
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660 #ifndef __CINT__
01661 #include "RooGlobalFunc.h"
01662 #endif
01663 #include "RooRealVar.h"
01664 #include "RooDataSet.h"
01665 #include "RooGaussian.h"
01666 #include "RooPolyVar.h"
01667 #include "RooPlot.h"
01668 #include "TCanvas.h"
01669 #include "TH1.h"
01670 using namespace RooFit ;
01671
01672
01673
01674 class TestBasic301 : public RooFitTestUnit
01675 {
01676 public:
01677 TestBasic301(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Composition extension of basic p.d.f",refFile,writeRef,verbose) {} ;
01678 Bool_t testCode() {
01679
01680
01681
01682
01683
01684 RooRealVar x("x","x",-5,5) ;
01685 RooRealVar y("y","y",-5,5) ;
01686
01687
01688 RooRealVar a0("a0","a0",-0.5,-5,5) ;
01689 RooRealVar a1("a1","a1",-0.5,-1,1) ;
01690 RooPolyVar fy("fy","fy",y,RooArgSet(a0,a1)) ;
01691
01692
01693 RooRealVar sigma("sigma","width of gaussian",0.5) ;
01694 RooGaussian model("model","Gaussian with shifting mean",x,fy,sigma) ;
01695
01696
01697
01698
01699
01700
01701 RooDataSet *data = model.generate(RooArgSet(x,y),10000) ;
01702
01703
01704 RooPlot* xframe = x.frame() ;
01705 data->plotOn(xframe) ;
01706 model.plotOn(xframe) ;
01707
01708
01709 RooPlot* yframe = y.frame() ;
01710 data->plotOn(yframe) ;
01711 model.plotOn(yframe) ;
01712
01713
01714 TH1* hh_model = model.createHistogram("hh_model",x,Binning(50),YVar(y,Binning(50))) ;
01715 hh_model->SetLineColor(kBlue) ;
01716
01717
01718 regPlot(xframe,"rf301_plot1") ;
01719 regPlot(yframe,"rf302_plot2") ;
01720 regTH(hh_model,"rf302_model2d") ;
01721
01722 delete data ;
01723 return kTRUE ;
01724 }
01725 } ;
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740 #ifndef __CINT__
01741 #include "RooGlobalFunc.h"
01742 #endif
01743 #include "RooRealVar.h"
01744 #include "RooDataSet.h"
01745 #include "RooGaussian.h"
01746 #include "TCanvas.h"
01747 #include "RooPlot.h"
01748 #include "RooFormulaVar.h"
01749 #include "RooAddition.h"
01750 #include "RooProduct.h"
01751 #include "RooPolyVar.h"
01752 #include "TCanvas.h"
01753 #include "TH1.h"
01754
01755 using namespace RooFit ;
01756
01757
01758 class TestBasic302 : public RooFitTestUnit
01759 {
01760 public:
01761 TestBasic302(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Sum and product utility functions",refFile,writeRef,verbose) {} ;
01762 Bool_t testCode() {
01763
01764
01765
01766
01767
01768 RooRealVar x("x","x",-5,5) ;
01769 RooRealVar y("y","y",-5,5) ;
01770
01771
01772 RooRealVar a0("a0","a0",-1.5,-5,5) ;
01773 RooRealVar a1("a1","a1",-0.5,-1,1) ;
01774 RooRealVar sigma("sigma","width of gaussian",0.5) ;
01775
01776
01777
01778
01779
01780
01781 RooFormulaVar fy_1("fy_1","a0-a1*sqrt(10*abs(y))",RooArgSet(y,a0,a1)) ;
01782
01783
01784 RooGaussian model_1("model_1","Gaussian with shifting mean",x,fy_1,sigma) ;
01785
01786
01787
01788
01789
01790
01791
01792 RooPolyVar fy_2("fy_2","fy_2",y,RooArgSet(a0,a1)) ;
01793
01794
01795 RooGaussian model_2("model_2","Gaussian with shifting mean",x,fy_2,sigma) ;
01796
01797
01798
01799
01800
01801
01802
01803 RooAddition fy_3("fy_3","a0+y",RooArgSet(a0,y)) ;
01804
01805
01806 RooGaussian model_3("model_3","Gaussian with shifting mean",x,fy_3,sigma) ;
01807
01808
01809
01810
01811
01812
01813
01814 RooProduct fy_4("fy_4","a1*y",RooArgSet(a1,y)) ;
01815
01816
01817 RooGaussian model_4("model_4","Gaussian with shifting mean",x,fy_4,sigma) ;
01818
01819
01820
01821
01822
01823
01824
01825 TH1* hh_model_1 = model_1.createHistogram("hh_model_1",x,Binning(50),YVar(y,Binning(50))) ;
01826 TH1* hh_model_2 = model_2.createHistogram("hh_model_2",x,Binning(50),YVar(y,Binning(50))) ;
01827 TH1* hh_model_3 = model_3.createHistogram("hh_model_3",x,Binning(50),YVar(y,Binning(50))) ;
01828 TH1* hh_model_4 = model_4.createHistogram("hh_model_4",x,Binning(50),YVar(y,Binning(50))) ;
01829 hh_model_1->SetLineColor(kBlue) ;
01830 hh_model_2->SetLineColor(kBlue) ;
01831 hh_model_3->SetLineColor(kBlue) ;
01832 hh_model_4->SetLineColor(kBlue) ;
01833
01834 regTH(hh_model_1,"rf202_model2d_1") ;
01835 regTH(hh_model_2,"rf202_model2d_2") ;
01836 regTH(hh_model_3,"rf202_model2d_3") ;
01837 regTH(hh_model_4,"rf202_model2d_4") ;
01838
01839 return kTRUE ;
01840 }
01841 } ;
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855 #ifndef __CINT__
01856 #include "RooGlobalFunc.h"
01857 #endif
01858 #include "RooRealVar.h"
01859 #include "RooDataSet.h"
01860 #include "RooGaussian.h"
01861 #include "RooPolyVar.h"
01862 #include "RooProdPdf.h"
01863 #include "RooPlot.h"
01864 #include "TRandom.h"
01865 #include "TCanvas.h"
01866 #include "TH1.h"
01867 using namespace RooFit ;
01868
01869
01870 class TestBasic303 : public RooFitTestUnit
01871 {
01872 public:
01873
01874 RooDataSet* makeFakeDataXY()
01875 {
01876 RooRealVar x("x","x",-10,10) ;
01877 RooRealVar y("y","y",-10,10) ;
01878 RooArgSet coord(x,y) ;
01879
01880 RooDataSet* d = new RooDataSet("d","d",RooArgSet(x,y)) ;
01881
01882 for (int i=0 ; i<10000 ; i++) {
01883 Double_t tmpy = gRandom->Gaus(0,10) ;
01884 Double_t tmpx = gRandom->Gaus(0.5*tmpy,1) ;
01885 if (fabs(tmpy)<10 && fabs(tmpx)<10) {
01886 x = tmpx ;
01887 y = tmpy ;
01888 d->add(coord) ;
01889 }
01890
01891 }
01892
01893 return d ;
01894 }
01895
01896
01897
01898 TestBasic303(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Conditional use of F(x|y)",refFile,writeRef,verbose) {} ;
01899 Bool_t testCode() {
01900
01901
01902
01903
01904
01905 RooRealVar x("x","x",-10,10) ;
01906 RooRealVar y("y","y",-10,10) ;
01907
01908
01909 RooRealVar a0("a0","a0",-0.5,-5,5) ;
01910 RooRealVar a1("a1","a1",-0.5,-1,1) ;
01911 RooPolyVar fy("fy","fy",y,RooArgSet(a0,a1)) ;
01912
01913
01914 RooRealVar sigma("sigma","width of gaussian",0.5,0.1,2.0) ;
01915 RooGaussian model("model","Gaussian with shifting mean",x,fy,sigma) ;
01916
01917
01918
01919 RooDataSet* expDataXY = makeFakeDataXY() ;
01920
01921
01922
01923
01924
01925
01926
01927 RooDataSet* expDataY= (RooDataSet*) expDataXY->reduce(y) ;
01928
01929
01930 RooDataSet *data = model.generate(x,ProtoData(*expDataY)) ;
01931
01932
01933
01934
01935
01936
01937 model.fitTo(*expDataXY,ConditionalObservables(y)) ;
01938
01939
01940
01941
01942
01943
01944
01945 RooPlot* xframe = x.frame() ;
01946 expDataXY->plotOn(xframe) ;
01947 model.plotOn(xframe,ProjWData(*expDataY)) ;
01948
01949
01950
01951 RooAbsData* binnedDataY = expDataY->binnedClone() ;
01952 model.plotOn(xframe,ProjWData(*binnedDataY),LineColor(kCyan),LineStyle(kDotted),Name("Alt1")) ;
01953
01954
01955
01956 ((RooRealVar*)expDataY->get()->find("y"))->setBins(5) ;
01957 RooAbsData* binnedDataY2 = expDataY->binnedClone() ;
01958 model.plotOn(xframe,ProjWData(*binnedDataY2),LineColor(kRed),Name("Alt2")) ;
01959
01960
01961 regPlot(xframe,"rf303_plot1") ;
01962
01963 delete binnedDataY ;
01964 delete binnedDataY2 ;
01965 delete expDataXY ;
01966 delete expDataY ;
01967 delete data ;
01968
01969 return kTRUE ;
01970 }
01971 } ;
01972
01973
01974
01975
01976
01977
01978
01979
01980
01981
01982
01983
01984
01985
01986
01987
01988
01989 #ifndef __CINT__
01990 #include "RooGlobalFunc.h"
01991 #endif
01992 #include "RooRealVar.h"
01993 #include "RooDataSet.h"
01994 #include "RooGaussian.h"
01995 #include "RooProdPdf.h"
01996 #include "TCanvas.h"
01997 #include "RooPlot.h"
01998 using namespace RooFit ;
01999
02000
02001
02002 class TestBasic304 : public RooFitTestUnit
02003 {
02004 public:
02005 TestBasic304(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Product operator p.d.f. with uncorrelated terms",refFile,writeRef,verbose) {} ;
02006 Bool_t testCode() {
02007
02008
02009
02010
02011
02012 RooRealVar x("x","x",-5,5) ;
02013 RooRealVar y("y","y",-5,5) ;
02014
02015 RooRealVar meanx("mean1","mean of gaussian x",2) ;
02016 RooRealVar meany("mean2","mean of gaussian y",-2) ;
02017 RooRealVar sigmax("sigmax","width of gaussian x",1) ;
02018 RooRealVar sigmay("sigmay","width of gaussian y",5) ;
02019
02020 RooGaussian gaussx("gaussx","gaussian PDF",x,meanx,sigmax) ;
02021 RooGaussian gaussy("gaussy","gaussian PDF",y,meany,sigmay) ;
02022
02023
02024
02025
02026
02027
02028
02029 RooProdPdf gaussxy("gaussxy","gaussx*gaussy",RooArgList(gaussx,gaussy)) ;
02030
02031
02032
02033
02034
02035
02036
02037 RooDataSet *data = gaussxy.generate(RooArgSet(x,y),10000) ;
02038
02039
02040 RooPlot* xframe = x.frame(Title("X projection of gauss(x)*gauss(y)")) ;
02041 data->plotOn(xframe) ;
02042 gaussxy.plotOn(xframe) ;
02043
02044
02045 RooPlot* yframe = y.frame(Title("Y projection of gauss(x)*gauss(y)")) ;
02046 data->plotOn(yframe) ;
02047 gaussxy.plotOn(yframe) ;
02048
02049 regPlot(xframe,"rf304_plot1") ;
02050 regPlot(yframe,"rf304_plot2") ;
02051
02052 delete data ;
02053
02054 return kTRUE ;
02055 }
02056 } ;
02057
02058
02059
02060
02061
02062
02063
02064
02065
02066
02067
02068
02069
02070
02071
02072
02073 #ifndef __CINT__
02074 #include "RooGlobalFunc.h"
02075 #endif
02076 #include "RooRealVar.h"
02077 #include "RooDataSet.h"
02078 #include "RooGaussian.h"
02079 #include "RooPolyVar.h"
02080 #include "RooProdPdf.h"
02081 #include "RooPlot.h"
02082 #include "TCanvas.h"
02083 #include "TH1.h"
02084 using namespace RooFit ;
02085
02086
02087
02088 class TestBasic305 : public RooFitTestUnit
02089 {
02090 public:
02091 TestBasic305(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Product operator p.d.f. with conditional term",refFile,writeRef,verbose) {} ;
02092 Bool_t testCode() {
02093
02094
02095
02096
02097
02098 RooRealVar x("x","x",-5,5) ;
02099 RooRealVar y("y","y",-5,5) ;
02100
02101
02102 RooRealVar a0("a0","a0",-0.5,-5,5) ;
02103 RooRealVar a1("a1","a1",-0.5,-1,1) ;
02104 RooPolyVar fy("fy","fy",y,RooArgSet(a0,a1)) ;
02105
02106
02107 RooRealVar sigmax("sigma","width of gaussian",0.5) ;
02108 RooGaussian gaussx("gaussx","Gaussian in x with shifting mean in y",x,fy,sigmax) ;
02109
02110
02111
02112
02113
02114
02115
02116 RooGaussian gaussy("gaussy","Gaussian in y",y,RooConst(0),RooConst(3)) ;
02117
02118
02119
02120
02121
02122
02123
02124 RooProdPdf model("model","gaussx(x|y)*gaussy(y)",gaussy,Conditional(gaussx,x)) ;
02125
02126
02127
02128
02129
02130
02131
02132 RooDataSet *data = model.generate(RooArgSet(x,y),10000) ;
02133
02134
02135 RooPlot* xframe = x.frame() ;
02136 data->plotOn(xframe) ;
02137 model.plotOn(xframe) ;
02138
02139
02140 RooPlot* yframe = y.frame() ;
02141 data->plotOn(yframe) ;
02142 model.plotOn(yframe) ;
02143
02144
02145 TH1* hh_model = model.createHistogram("hh_model_rf305",x,Binning(50),YVar(y,Binning(50))) ;
02146 hh_model->SetLineColor(kBlue) ;
02147
02148 regTH(hh_model,"rf305_model2d") ;
02149 regPlot(xframe,"rf305_plot1") ;
02150 regPlot(yframe,"rf305_plot2") ;
02151
02152 delete data ;
02153
02154 return kTRUE ;
02155
02156 }
02157 } ;
02158
02159
02160
02161
02162
02163
02164
02165
02166
02167
02168
02169
02170
02171
02172
02173 #ifndef __CINT__
02174 #include "RooGlobalFunc.h"
02175 #endif
02176 #include "RooRealVar.h"
02177 #include "RooDataSet.h"
02178 #include "RooGaussian.h"
02179 #include "RooGaussModel.h"
02180 #include "RooDecay.h"
02181 #include "RooLandau.h"
02182 #include "RooPlot.h"
02183 #include "TCanvas.h"
02184 #include "TH2D.h"
02185 using namespace RooFit ;
02186
02187
02188
02189 class TestBasic306 : public RooFitTestUnit
02190 {
02191 public:
02192 TestBasic306(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Conditional use of per-event error p.d.f. F(t|dt)",refFile,writeRef,verbose) {} ;
02193 Bool_t testCode() {
02194
02195
02196
02197
02198
02199 RooRealVar dt("dt","dt",-10,10) ;
02200 RooRealVar dterr("dterr","per-event error on dt",0.01,10) ;
02201
02202
02203 RooRealVar bias("bias","bias",0,-10,10) ;
02204 RooRealVar sigma("sigma","per-event error scale factor",1,0.1,10) ;
02205 RooGaussModel gm("gm1","gauss model scaled bt per-event error",dt,bias,sigma,dterr) ;
02206
02207
02208 RooRealVar tau("tau","tau",1.548) ;
02209 RooDecay decay_gm("decay_gm","decay",dt,tau,gm,RooDecay::DoubleSided) ;
02210
02211
02212
02213
02214
02215
02216
02217 RooLandau pdfDtErr("pdfDtErr","pdfDtErr",dterr,RooConst(1),RooConst(0.25)) ;
02218 RooDataSet* expDataDterr = pdfDtErr.generate(dterr,10000) ;
02219
02220
02221
02222
02223
02224
02225
02226 RooDataSet* data = decay_gm.generate(dt,ProtoData(*expDataDterr)) ;
02227
02228
02229
02230
02231
02232
02233
02234 decay_gm.fitTo(*data,ConditionalObservables(dterr)) ;
02235
02236
02237
02238
02239
02240
02241
02242
02243 TH1* hh_decay = decay_gm.createHistogram("hh_decay",dt,Binning(50),YVar(dterr,Binning(50))) ;
02244 hh_decay->SetLineColor(kBlue) ;
02245
02246
02247
02248 RooPlot* frame = dt.frame(Title("Slices of decay(dt|dterr) at various dterr")) ;
02249 for (Int_t ibin=0 ; ibin<100 ; ibin+=20) {
02250 dterr.setBin(ibin) ;
02251 decay_gm.plotOn(frame,Normalization(5.),Name(Form("curve_slice_%d",ibin))) ;
02252 }
02253
02254
02255
02256 RooPlot* frame2 = dt.frame(Title("Projection of decay(dt|dterr) on dt")) ;
02257 data->plotOn(frame2) ;
02258
02259
02260
02261
02262
02263
02264 decay_gm.plotOn(frame2,ProjWData(*expDataDterr,kTRUE)) ;
02265
02266
02267 regTH(hh_decay,"rf306_model2d") ;
02268 regPlot(frame,"rf306_plot1") ;
02269 regPlot(frame2,"rf306_plot2") ;
02270
02271 delete expDataDterr ;
02272 delete data ;
02273
02274 return kTRUE ;
02275 }
02276 } ;
02277
02278
02279
02280
02281
02282
02283
02284
02285
02286
02287
02288
02289
02290 #ifndef __CINT__
02291 #include "RooGlobalFunc.h"
02292 #endif
02293 #include "RooRealVar.h"
02294 #include "RooDataSet.h"
02295 #include "RooGaussian.h"
02296 #include "RooGaussModel.h"
02297 #include "RooDecay.h"
02298 #include "RooLandau.h"
02299 #include "RooProdPdf.h"
02300 #include "RooHistPdf.h"
02301 #include "RooPlot.h"
02302 #include "TCanvas.h"
02303 #include "TH1.h"
02304 using namespace RooFit ;
02305
02306
02307 class TestBasic307 : public RooFitTestUnit
02308 {
02309 public:
02310 TestBasic307(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Full per-event error p.d.f. F(t|dt)G(dt)",refFile,writeRef,verbose) {} ;
02311 Bool_t testCode() {
02312
02313
02314
02315
02316
02317 RooRealVar dt("dt","dt",-10,10) ;
02318 RooRealVar dterr("dterr","per-event error on dt",0.1,10) ;
02319
02320
02321 RooRealVar bias("bias","bias",0,-10,10) ;
02322 RooRealVar sigma("sigma","per-event error scale factor",1,0.1,10) ;
02323 RooGaussModel gm("gm1","gauss model scaled bt per-event error",dt,bias,sigma,dterr) ;
02324
02325
02326 RooRealVar tau("tau","tau",1.548) ;
02327 RooDecay decay_gm("decay_gm","decay",dt,tau,gm,RooDecay::DoubleSided) ;
02328
02329
02330
02331
02332
02333
02334
02335 RooLandau pdfDtErr("pdfDtErr","pdfDtErr",dterr,RooConst(1),RooConst(0.25)) ;
02336 RooDataSet* expDataDterr = pdfDtErr.generate(dterr,10000) ;
02337
02338
02339 RooDataHist* expHistDterr = expDataDterr->binnedClone() ;
02340 RooHistPdf pdfErr("pdfErr","pdfErr",dterr,*expHistDterr) ;
02341
02342
02343
02344
02345
02346
02347 RooProdPdf model("model","model",pdfErr,Conditional(decay_gm,dt)) ;
02348
02349
02350
02351
02352
02353
02354
02355
02356
02357
02358 RooDataSet* data = model.generate(RooArgSet(dt,dterr),10000) ;
02359
02360
02361
02362
02363
02364
02365
02366 model.fitTo(*data) ;
02367
02368
02369
02370
02371
02372
02373
02374
02375 RooPlot* frame = dt.frame(Title("Projection of model(dt|dterr) on dt")) ;
02376 data->plotOn(frame) ;
02377 model.plotOn(frame) ;
02378
02379
02380 regPlot(frame,"rf307_plot1") ;
02381
02382 delete expDataDterr ;
02383 delete expHistDterr ;
02384 delete data ;
02385
02386 return kTRUE ;
02387
02388 }
02389 } ;
02390
02391
02392
02393
02394
02395
02396
02397
02398
02399
02400
02401
02402
02403 #ifndef __CINT__
02404 #include "RooGlobalFunc.h"
02405 #endif
02406 #include "RooRealVar.h"
02407 #include "RooGaussian.h"
02408 #include "RooProdPdf.h"
02409 #include "RooAbsReal.h"
02410 #include "RooPlot.h"
02411 #include "TCanvas.h"
02412 #include "TH1.h"
02413 using namespace RooFit ;
02414
02415
02416 class TestBasic308 : public RooFitTestUnit
02417 {
02418 public:
02419 TestBasic308(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Normalization of p.d.f.s in 2D",refFile,writeRef,verbose) {} ;
02420 Bool_t testCode() {
02421
02422
02423
02424
02425
02426 RooRealVar x("x","x",-10,10) ;
02427 RooRealVar y("y","y",-10,10) ;
02428
02429
02430 RooGaussian gx("gx","gx",x,RooConst(-2),RooConst(3)) ;
02431 RooGaussian gy("gy","gy",y,RooConst(+2),RooConst(2)) ;
02432
02433
02434 RooProdPdf gxy("gxy","gxy",RooArgSet(gx,gy)) ;
02435
02436
02437
02438
02439
02440
02441
02442 regValue(gxy.getVal(),"rf308_gxy") ;
02443
02444
02445 RooArgSet nset_xy(x,y) ;
02446 regValue(gxy.getVal(&nset_xy),"rf308_gx_Norm[x,y]") ;
02447
02448
02449
02450 RooAbsReal* igxy = gxy.createIntegral(RooArgSet(x,y)) ;
02451 regValue(igxy->getVal(),"rf308_gx_Int[x,y]") ;
02452
02453
02454
02455
02456 RooArgSet nset_x(x) ;
02457 regValue(gxy.getVal(&nset_x),"rf308_gx_Norm[x]") ;
02458
02459
02460 RooArgSet nset_y(y) ;
02461 regValue(gxy.getVal(&nset_y),"rf308_gx_Norm[y]") ;
02462
02463
02464
02465
02466
02467
02468
02469 x.setRange("signal",-5,5) ;
02470 y.setRange("signal",-3,3) ;
02471
02472
02473
02474
02475 RooAbsReal* igxy_sig = gxy.createIntegral(RooArgSet(x,y),NormSet(RooArgSet(x,y)),Range("signal")) ;
02476 regValue(igxy_sig->getVal(),"rf308_gx_Int[x,y|signal]_Norm[x,y]") ;
02477
02478
02479
02480
02481
02482
02483
02484
02485 RooAbsReal* gxy_cdf = gxy.createCdf(RooArgSet(x,y)) ;
02486
02487
02488 TH1* hh_cdf = gxy_cdf->createHistogram("hh_cdf",x,Binning(40),YVar(y,Binning(40))) ;
02489
02490 regTH(hh_cdf,"rf308_cdf") ;
02491
02492 delete igxy_sig ;
02493 delete igxy ;
02494 delete gxy_cdf ;
02495
02496 return kTRUE ;
02497 }
02498 } ;
02499
02500
02501
02502
02503
02504
02505
02506
02507
02508
02509
02510
02511 #ifndef __CINT__
02512 #include "RooGlobalFunc.h"
02513 #endif
02514 #include "RooRealVar.h"
02515 #include "RooDataSet.h"
02516 #include "RooGaussModel.h"
02517 #include "RooDecay.h"
02518 #include "RooBMixDecay.h"
02519 #include "RooCategory.h"
02520 #include "TCanvas.h"
02521 #include "RooPlot.h"
02522 using namespace RooFit ;
02523
02524
02525 class TestBasic310 : public RooFitTestUnit
02526 {
02527 public:
02528 TestBasic310(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Data and p.d.f projection in category slice",refFile,writeRef,verbose) {} ;
02529 Bool_t testCode() {
02530
02531
02532
02533
02534
02535 RooRealVar dt("dt","dt",-20,20) ;
02536
02537
02538 RooCategory mixState("mixState","B0/B0bar mixing state") ;
02539 RooCategory tagFlav("tagFlav","Flavour of the tagged B0") ;
02540
02541
02542 mixState.defineType("mixed",-1) ;
02543 mixState.defineType("unmixed",1) ;
02544 tagFlav.defineType("B0",1) ;
02545 tagFlav.defineType("B0bar",-1) ;
02546
02547
02548 RooRealVar dm("dm","delta m(B)",0.472,0.,1.0) ;
02549 RooRealVar tau("tau","B0 decay time",1.547,1.0,2.0) ;
02550 RooRealVar w("w","Flavor Mistag rate",0.03,0.0,1.0) ;
02551 RooRealVar dw("dw","Flavor Mistag rate difference between B0 and B0bar",0.01) ;
02552
02553
02554 RooRealVar bias1("bias1","bias1",0) ;
02555 RooRealVar sigma1("sigma1","sigma1",0.01) ;
02556 RooGaussModel gm1("gm1","gauss model 1",dt,bias1,sigma1) ;
02557
02558
02559 RooBMixDecay bmix_gm1("bmix","decay",dt,mixState,tagFlav,tau,dm,w,dw,gm1,RooBMixDecay::DoubleSided) ;
02560
02561
02562 RooDataSet *data = bmix_gm1.generate(RooArgSet(dt,tagFlav,mixState),20000) ;
02563
02564
02565
02566
02567
02568
02569
02570 RooPlot* frame = dt.frame(Title("Inclusive decay distribution")) ;
02571 data->plotOn(frame) ;
02572 bmix_gm1.plotOn(frame) ;
02573
02574
02575
02576
02577
02578
02579
02580 RooPlot* frame2 = dt.frame(Title("Decay distribution of mixed events")) ;
02581 data->plotOn(frame2,Cut("mixState==mixState::mixed")) ;
02582
02583
02584 bmix_gm1.plotOn(frame2,Slice(mixState,"mixed")) ;
02585
02586
02587 RooPlot* frame3 = dt.frame(Title("Decay distribution of unmixed events")) ;
02588 data->plotOn(frame3,Cut("mixState==mixState::unmixed")) ;
02589
02590
02591 bmix_gm1.plotOn(frame3,Slice(mixState,"unmixed")) ;
02592
02593
02594 regPlot(frame,"rf310_plot1") ;
02595 regPlot(frame2,"rf310_plot2") ;
02596 regPlot(frame3,"rf310_plot3") ;
02597
02598 delete data ;
02599
02600 return kTRUE ;
02601 }
02602 } ;
02603
02604
02605
02606
02607
02608
02609
02610
02611
02612
02613
02614
02615 #ifndef __CINT__
02616 #include "RooGlobalFunc.h"
02617 #endif
02618 #include "RooRealVar.h"
02619 #include "RooDataSet.h"
02620 #include "RooGaussian.h"
02621 #include "RooProdPdf.h"
02622 #include "RooAddPdf.h"
02623 #include "RooPolynomial.h"
02624 #include "TCanvas.h"
02625 #include "RooPlot.h"
02626 using namespace RooFit ;
02627
02628
02629 class TestBasic311 : public RooFitTestUnit
02630 {
02631 public:
02632 TestBasic311(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Data and p.d.f projection in sub range",refFile,writeRef,verbose) {} ;
02633 Bool_t testCode() {
02634
02635
02636
02637
02638
02639 RooRealVar x("x","x",-5,5) ;
02640 RooRealVar y("y","y",-5,5) ;
02641 RooRealVar z("z","z",-5,5) ;
02642
02643
02644 RooGaussian gx("gx","gx",x,RooConst(0),RooConst(1)) ;
02645 RooGaussian gy("gy","gy",y,RooConst(0),RooConst(1)) ;
02646 RooGaussian gz("gz","gz",z,RooConst(0),RooConst(1)) ;
02647 RooProdPdf sig("sig","sig",RooArgSet(gx,gy,gz)) ;
02648
02649
02650 RooPolynomial px("px","px",x,RooArgSet(RooConst(-0.1),RooConst(0.004))) ;
02651 RooPolynomial py("py","py",y,RooArgSet(RooConst(0.1),RooConst(-0.004))) ;
02652 RooPolynomial pz("pz","pz",z) ;
02653 RooProdPdf bkg("bkg","bkg",RooArgSet(px,py,pz)) ;
02654
02655
02656 RooRealVar fsig("fsig","signal fraction",0.1,0.,1.) ;
02657 RooAddPdf model("model","model",RooArgList(sig,bkg),fsig) ;
02658
02659 RooDataSet* data = model.generate(RooArgSet(x,y,z),20000) ;
02660
02661
02662
02663
02664
02665
02666
02667 RooPlot* frame = x.frame(Title("Projection of 3D data and pdf on X"),Bins(40)) ;
02668 data->plotOn(frame) ;
02669 model.plotOn(frame) ;
02670
02671
02672
02673
02674
02675
02676
02677 y.setRange("sigRegion",-1,1) ;
02678 z.setRange("sigRegion",-1,1) ;
02679
02680
02681 RooPlot* frame2 = x.frame(Title("Same projection on X in signal range of (Y,Z)"),Bins(40)) ;
02682
02683
02684
02685
02686 data->plotOn(frame2,CutRange("sigRegion")) ;
02687
02688
02689 model.plotOn(frame2,ProjectionRange("sigRegion")) ;
02690
02691
02692 regPlot(frame,"rf311_plot1") ;
02693 regPlot(frame2,"rf312_plot2") ;
02694
02695 delete data ;
02696
02697 return kTRUE ;
02698 }
02699 } ;
02700
02701
02702
02703
02704
02705
02706
02707
02708
02709
02710
02711
02712 #ifndef __CINT__
02713 #include "RooGlobalFunc.h"
02714 #endif
02715 #include "RooRealVar.h"
02716 #include "RooDataSet.h"
02717 #include "RooGaussian.h"
02718 #include "RooProdPdf.h"
02719 #include "RooAddPdf.h"
02720 #include "RooPolynomial.h"
02721 #include "TCanvas.h"
02722 #include "RooPlot.h"
02723 #include "RooFitResult.h"
02724 using namespace RooFit ;
02725
02726
02727 class TestBasic312 : public RooFitTestUnit
02728 {
02729 public:
02730 TestBasic312(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Fit in multiple rectangular ranges",refFile,writeRef,verbose) {} ;
02731 Bool_t testCode() {
02732
02733
02734
02735
02736
02737 RooRealVar x("x","x",-10,10) ;
02738 RooRealVar y("y","y",-10,10) ;
02739
02740
02741 RooRealVar mx("mx","mx",1,-10,10) ;
02742 RooRealVar my("my","my",1,-10,10) ;
02743
02744 RooGaussian gx("gx","gx",x,mx,RooConst(1)) ;
02745 RooGaussian gy("gy","gy",y,my,RooConst(1)) ;
02746
02747 RooProdPdf sig("sig","sig",gx,gy) ;
02748
02749
02750 RooPolynomial px("px","px",x) ;
02751 RooPolynomial py("py","py",y) ;
02752 RooProdPdf bkg("bkg","bkg",px,py) ;
02753
02754
02755 RooRealVar f("f","f",0.,1.) ;
02756 RooAddPdf model("model","model",RooArgList(sig,bkg),f) ;
02757
02758
02759 RooDataSet* modelData = model.generate(RooArgSet(x,y),10000) ;
02760
02761
02762
02763
02764
02765
02766
02767
02768
02769
02770
02771
02772
02773
02774
02775
02776
02777
02778
02779
02780
02781
02782 x.setRange("SB1",-10,+10) ;
02783 y.setRange("SB1",-10,0) ;
02784
02785 x.setRange("SB2",-10,0) ;
02786 y.setRange("SB2",0,+10) ;
02787
02788 x.setRange("SIG",0,+10) ;
02789 y.setRange("SIG",0,+10) ;
02790
02791 x.setRange("FULL",-10,+10) ;
02792 y.setRange("FULL",-10,+10) ;
02793
02794
02795
02796
02797
02798
02799 RooFitResult* r_sb1 = model.fitTo(*modelData,Range("SB1"),Save()) ;
02800
02801
02802 RooFitResult* r_sb2 = model.fitTo(*modelData,Range("SB2"),Save()) ;
02803
02804
02805
02806
02807
02808
02809
02810
02811 RooFitResult* r_sb12 = model.fitTo(*modelData,Range("SB1,SB2"),Save()) ;
02812
02813
02814 regResult(r_sb1,"rf312_fit_sb1") ;
02815 regResult(r_sb2,"rf312_fit_sb2") ;
02816 regResult(r_sb12,"rf312_fit_sb12") ;
02817
02818 delete modelData ;
02819
02820 return kTRUE ;
02821
02822 }
02823 } ;
02824
02825
02826
02827
02828
02829
02830
02831
02832
02833
02834
02835
02836
02837 #ifndef __CINT__
02838 #include "RooGlobalFunc.h"
02839 #endif
02840 #include "RooRealVar.h"
02841 #include "RooDataSet.h"
02842 #include "RooGaussian.h"
02843 #include "RooPolynomial.h"
02844 #include "RooProdPdf.h"
02845 #include "TCanvas.h"
02846 #include "RooPlot.h"
02847 using namespace RooFit ;
02848
02849
02850 class TestBasic313 : public RooFitTestUnit
02851 {
02852 public:
02853 TestBasic313(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Integration over non-rectangular regions",refFile,writeRef,verbose) {} ;
02854 Bool_t testCode() {
02855
02856
02857
02858
02859
02860 RooRealVar x("x","x",0,10) ;
02861 RooRealVar y("y","y",0,10) ;
02862 RooRealVar z("z","z",0,10) ;
02863
02864
02865 RooRealVar z0("z0","z0",-0.1,1) ;
02866 RooPolynomial px("px","px",x,RooConst(0)) ;
02867 RooPolynomial py("py","py",y,RooConst(0)) ;
02868 RooPolynomial pz("pz","pz",z,z0) ;
02869 RooProdPdf pxyz("pxyz","pxyz",RooArgSet(px,py,pz)) ;
02870
02871
02872
02873
02874
02875
02876
02877
02878
02879
02880
02881 RooFormulaVar ylo("ylo","0.1*x",x) ;
02882 RooFormulaVar yhi("yhi","0.9*x",x) ;
02883 y.setRange("R",ylo,yhi) ;
02884
02885
02886 RooFormulaVar zlo("zlo","0.0*y",y) ;
02887 RooFormulaVar zhi("zhi","0.1*y*y",y) ;
02888 z.setRange("R",zlo,zhi) ;
02889
02890
02891
02892
02893
02894
02895
02896 RooAbsReal* intPdf = pxyz.createIntegral(RooArgSet(x,y,z),RooArgSet(x,y,z),"R") ;
02897
02898
02899 RooPlot* frame = z0.frame(Title("Integral of pxyz over x,y,z in region R")) ;
02900 intPdf->plotOn(frame) ;
02901
02902
02903 regPlot(frame,"rf313_plot1") ;
02904
02905 delete intPdf ;
02906
02907 return kTRUE;
02908 }
02909 } ;
02910
02911
02912
02913
02914
02915
02916
02917
02918
02919
02920
02921
02922
02923
02924
02925 #ifndef __CINT__
02926 #include "RooGlobalFunc.h"
02927 #endif
02928 #include "RooRealVar.h"
02929 #include "RooDataSet.h"
02930 #include "RooGaussian.h"
02931 #include "RooExponential.h"
02932 #include "TCanvas.h"
02933 #include "RooPlot.h"
02934 #include "RooFitResult.h"
02935
02936 using namespace RooFit ;
02937
02938
02939 class TestBasic314 : public RooFitTestUnit
02940 {
02941 public:
02942 TestBasic314(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Fit with non-rectangular observable boundaries",refFile,writeRef,verbose) {} ;
02943 Bool_t testCode() {
02944
02945
02946
02947
02948
02949 RooRealVar t("t","t",0,5) ;
02950 RooRealVar tmin("tmin","tmin",0,0,5) ;
02951
02952
02953 t.setRange(tmin,RooConst(t.getMax())) ;
02954
02955
02956 RooRealVar tau("tau","tau",-1.54,-10,-0.1) ;
02957 RooExponential model("model","model",t,tau) ;
02958
02959
02960
02961
02962
02963
02964
02965 RooDataSet* dall = model.generate(t,10000) ;
02966
02967
02968 RooDataSet* tmp = RooGaussian("gmin","gmin",tmin,RooConst(0),RooConst(0.5)).generate(tmin,5000) ;
02969
02970
02971 RooDataSet* dacc = model.generate(t,ProtoData(*tmp)) ;
02972
02973
02974
02975
02976
02977
02978 RooFitResult* r = model.fitTo(*dacc,Save()) ;
02979
02980
02981
02982
02983
02984
02985
02986 RooPlot* frame = t.frame(Title("Fit to data with per-event acceptance")) ;
02987 dall->plotOn(frame,MarkerColor(kRed),LineColor(kRed)) ;
02988 model.plotOn(frame) ;
02989 dacc->plotOn(frame,Name("dacc")) ;
02990
02991
02992 regResult(r,"rf314_fit") ;
02993 regPlot(frame,"rf314_plot1") ;
02994
02995 delete tmp ;
02996 delete dacc ;
02997 delete dall ;
02998
02999 return kTRUE;
03000 }
03001 } ;
03002
03003
03004
03005
03006
03007
03008
03009
03010
03011
03012
03013
03014
03015
03016 #ifndef __CINT__
03017 #include "RooGlobalFunc.h"
03018 #endif
03019 #include "RooRealVar.h"
03020 #include "RooDataSet.h"
03021 #include "RooGaussian.h"
03022 #include "RooProdPdf.h"
03023 #include "RooPolyVar.h"
03024 #include "TH1.h"
03025 #include "TCanvas.h"
03026 #include "RooPlot.h"
03027 #include "RooNumIntConfig.h"
03028 #include "RooConstVar.h"
03029 using namespace RooFit ;
03030
03031
03032
03033 class TestBasic315 : public RooFitTestUnit
03034 {
03035 public:
03036 TestBasic315(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("P.d.f. marginalization through integration",refFile,writeRef,verbose) {} ;
03037 Bool_t testCode() {
03038
03039
03040
03041
03042
03043
03044 RooAbsPdf::defaultIntegratorConfig()->setEpsRel(1e-8) ;
03045 RooAbsPdf::defaultIntegratorConfig()->setEpsAbs(1e-8) ;
03046
03047
03048 RooRealVar x("x","x",-5,5) ;
03049 RooRealVar y("y","y",-2,2) ;
03050
03051
03052 RooRealVar a0("a0","a0",0) ;
03053 RooRealVar a1("a1","a1",-1.5,-3,1) ;
03054 RooPolyVar fy("fy","fy",y,RooArgSet(a0,a1)) ;
03055
03056
03057 RooRealVar sigmax("sigmax","width of gaussian",0.5) ;
03058 RooGaussian gaussx("gaussx","Gaussian in x with shifting mean in y",x,fy,sigmax) ;
03059
03060
03061 RooGaussian gaussy("gaussy","Gaussian in y",y,RooConst(0),RooConst(2)) ;
03062
03063
03064 RooProdPdf model("model","gaussx(x|y)*gaussy(y)",gaussy,Conditional(gaussx,x)) ;
03065
03066
03067
03068
03069
03070
03071
03072 RooAbsPdf* modelx = model.createProjection(y) ;
03073
03074
03075
03076
03077
03078
03079
03080 RooAbsData* data = modelx->generateBinned(x,1000) ;
03081
03082
03083 modelx->fitTo(*data) ;
03084
03085
03086 RooPlot* frame = x.frame(40) ;
03087 data->plotOn(frame) ;
03088 modelx->plotOn(frame) ;
03089
03090 regPlot(frame,"rf315_frame") ;
03091
03092 delete data ;
03093 delete modelx ;
03094
03095 return kTRUE ;
03096 }
03097 } ;
03098
03099
03100
03101
03102
03103
03104
03105
03106
03107
03108
03109
03110
03111
03112
03113
03114
03115
03116 #ifndef __CINT__
03117 #include "RooGlobalFunc.h"
03118 #endif
03119 #include "RooRealVar.h"
03120 #include "RooDataSet.h"
03121 #include "RooGaussian.h"
03122 #include "RooPolynomial.h"
03123 #include "RooAddPdf.h"
03124 #include "RooProdPdf.h"
03125 #include "TCanvas.h"
03126 #include "RooPlot.h"
03127 using namespace RooFit ;
03128
03129
03130 class TestBasic316 : public RooFitTestUnit
03131 {
03132 public:
03133 TestBasic316(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Likelihood ratio projection plot",refFile,writeRef,verbose) {} ;
03134 Bool_t testCode() {
03135
03136
03137
03138
03139
03140 RooRealVar x("x","x",-5,5) ;
03141 RooRealVar y("y","y",-5,5) ;
03142 RooRealVar z("z","z",-5,5) ;
03143
03144
03145 RooGaussian gx("gx","gx",x,RooConst(0),RooConst(1)) ;
03146 RooGaussian gy("gy","gy",y,RooConst(0),RooConst(1)) ;
03147 RooGaussian gz("gz","gz",z,RooConst(0),RooConst(1)) ;
03148 RooProdPdf sig("sig","sig",RooArgSet(gx,gy,gz)) ;
03149
03150
03151 RooPolynomial px("px","px",x,RooArgSet(RooConst(-0.1),RooConst(0.004))) ;
03152 RooPolynomial py("py","py",y,RooArgSet(RooConst(0.1),RooConst(-0.004))) ;
03153 RooPolynomial pz("pz","pz",z) ;
03154 RooProdPdf bkg("bkg","bkg",RooArgSet(px,py,pz)) ;
03155
03156
03157 RooRealVar fsig("fsig","signal fraction",0.1,0.,1.) ;
03158 RooAddPdf model("model","model",RooArgList(sig,bkg),fsig) ;
03159
03160 RooDataSet* data = model.generate(RooArgSet(x,y,z),20000) ;
03161
03162
03163
03164
03165
03166
03167
03168 RooPlot* frame = x.frame(Title("Projection of 3D data and pdf on X"),Bins(40)) ;
03169 data->plotOn(frame) ;
03170 model.plotOn(frame) ;
03171
03172
03173
03174
03175
03176
03177
03178
03179 RooAbsPdf* sigyz = sig.createProjection(x) ;
03180 RooAbsPdf* totyz = model.createProjection(x) ;
03181
03182
03183 RooFormulaVar llratio_func("llratio","log10(@0)-log10(@1)",RooArgList(*sigyz,*totyz)) ;
03184
03185
03186
03187
03188
03189
03190
03191 data->addColumn(llratio_func) ;
03192
03193
03194 RooDataSet* dataSel = (RooDataSet*) data->reduce(Cut("llratio>0.7")) ;
03195
03196
03197 RooPlot* frame2 = x.frame(Title("Same projection on X with LLratio(y,z)>0.7"),Bins(40)) ;
03198
03199
03200 dataSel->plotOn(frame2) ;
03201
03202
03203
03204
03205
03206
03207
03208 RooDataSet* mcprojData = model.generate(RooArgSet(x,y,z),10000) ;
03209
03210
03211 mcprojData->addColumn(llratio_func) ;
03212 RooDataSet* mcprojDataSel = (RooDataSet*) mcprojData->reduce(Cut("llratio>0.7")) ;
03213
03214
03215
03216 model.plotOn(frame2,ProjWData(*mcprojDataSel)) ;
03217
03218
03219 regPlot(frame,"rf316_plot1") ;
03220 regPlot(frame2,"rf316_plot2") ;
03221
03222 delete data ;
03223 delete dataSel ;
03224 delete mcprojData ;
03225 delete mcprojDataSel ;
03226 delete sigyz ;
03227 delete totyz ;
03228
03229 return kTRUE ;
03230 }
03231 } ;
03232
03233
03234
03235
03236
03237
03238
03239
03240
03241
03242
03243
03244 #ifndef __CINT__
03245 #include "RooGlobalFunc.h"
03246 #endif
03247 #include "RooRealVar.h"
03248 #include "RooDataSet.h"
03249 #include "RooDataHist.h"
03250 #include "RooGaussian.h"
03251 #include "RooCategory.h"
03252 #include "TCanvas.h"
03253 #include "RooPlot.h"
03254 #include "TFile.h"
03255 using namespace RooFit ;
03256
03257
03258 class TestBasic402 : public RooFitTestUnit
03259 {
03260 public:
03261 TestBasic402(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Basic operations on datasets",refFile,writeRef,verbose) {} ;
03262 Bool_t testCode() {
03263
03264
03265
03266
03267
03268
03269 RooRealVar x("x","x",-10,10) ;
03270 RooRealVar y("y","y", 0, 40) ;
03271 RooCategory c("c","c") ;
03272 c.defineType("Plus",+1) ;
03273 c.defineType("Minus",-1) ;
03274
03275
03276
03277
03278
03279
03280
03281 RooDataSet d("d","d",RooArgSet(x,y,c)) ;
03282
03283
03284
03285
03286
03287
03288 Int_t i ;
03289 for (i=0 ; i<1000 ; i++) {
03290 x = i/50 - 10 ;
03291 y = sqrt(1.0*i) ;
03292 c.setLabel((i%2)?"Plus":"Minus") ;
03293
03294
03295
03296 d.add(RooArgSet(x,y,c)) ;
03297 }
03298
03299
03300
03301
03302
03303
03304 RooDataSet* d1 = (RooDataSet*) d.reduce(RooArgSet(x,c)) ;
03305 RooDataSet* d2 = (RooDataSet*) d.reduce(RooArgSet(y)) ;
03306 RooDataSet* d3 = (RooDataSet*) d.reduce("y>5.17") ;
03307 RooDataSet* d4 = (RooDataSet*) d.reduce(RooArgSet(x,c),"y>5.17") ;
03308
03309 regValue(d3->numEntries(),"rf403_nd3") ;
03310 regValue(d4->numEntries(),"rf403_nd4") ;
03311
03312
03313 d1->merge(d2) ;
03314
03315
03316 d1->append(*d3) ;
03317
03318 regValue(d1->numEntries(),"rf403_nd1") ;
03319
03320
03321
03322
03323
03324
03325
03326
03327
03328
03329
03330
03331
03332 x.setBins(10) ;
03333 y.setBins(10) ;
03334 RooDataHist dh("dh","binned version of d",RooArgSet(x,y),d) ;
03335
03336 RooPlot* yframe = y.frame(Bins(10),Title("Operations on binned datasets")) ;
03337 dh.plotOn(yframe) ;
03338
03339
03340
03341
03342
03343 RooDataHist* dh2 = (RooDataHist*) dh.reduce(y,"x>0") ;
03344
03345
03346 dh2->plotOn(yframe,LineColor(kRed),MarkerColor(kRed),Name("dh2")) ;
03347
03348 regPlot(yframe,"rf402_plot1") ;
03349
03350 delete d1 ;
03351 delete d2 ;
03352 delete d3 ;
03353 delete d4 ;
03354 delete dh2 ;
03355 return kTRUE ;
03356 }
03357 } ;
03358
03359
03360
03361
03362
03363
03364
03365
03366
03367
03368
03369
03370 #ifndef __CINT__
03371 #include "RooGlobalFunc.h"
03372 #endif
03373 #include "RooRealVar.h"
03374 #include "RooDataSet.h"
03375 #include "RooDataHist.h"
03376 #include "RooGaussian.h"
03377 #include "RooFormulaVar.h"
03378 #include "RooGenericPdf.h"
03379 #include "RooPolynomial.h"
03380 #include "RooChi2Var.h"
03381 #include "RooMinuit.h"
03382 #include "TCanvas.h"
03383 #include "RooPlot.h"
03384 #include "RooFitResult.h"
03385 using namespace RooFit ;
03386
03387
03388 class TestBasic403 : public RooFitTestUnit
03389 {
03390 public:
03391 TestBasic403(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Fits with weighted datasets",refFile,writeRef,verbose) {} ;
03392 Bool_t testCode() {
03393
03394
03395
03396
03397
03398 RooRealVar x("x","x",-10,10) ;
03399 x.setBins(40) ;
03400
03401
03402 RooPolynomial p0("px","px",x) ;
03403
03404
03405 RooDataSet* data = p0.generate(x,1000) ;
03406
03407
03408
03409
03410
03411
03412
03413 RooFormulaVar wFunc("w","event weight","(x*x+10)",x) ;
03414
03415
03416 RooRealVar* w = (RooRealVar*) data->addColumn(wFunc) ;
03417
03418
03419 RooDataSet dataw(data->GetName(),data->GetTitle(),data,*data->get(),0,w->GetName()) ;
03420
03421
03422
03423
03424
03425
03426
03427 RooRealVar a0("a0","a0",1) ;
03428 RooRealVar a1("a1","a1",0,-1,1) ;
03429 RooRealVar a2("a2","a2",1,0,10) ;
03430 RooPolynomial p2("p2","p2",x,RooArgList(a0,a1,a2),0) ;
03431
03432
03433
03434
03435
03436
03437
03438
03439 RooFitResult* r_ml_wgt = p2.fitTo(dataw,Save()) ;
03440
03441
03442
03443
03444
03445
03446
03447 RooPlot* frame = x.frame(Title("Unbinned ML fit, binned chi^2 fit to weighted data")) ;
03448
03449
03450 dataw.plotOn(frame,DataError(RooAbsData::SumW2)) ;
03451
03452
03453 p2.plotOn(frame) ;
03454
03455
03456
03457
03458
03459
03460
03461 RooGenericPdf genPdf("genPdf","x*x+10",x) ;
03462
03463
03464 RooDataSet* data2 = genPdf.generate(x,1000) ;
03465
03466
03467 RooDataSet* data3 = genPdf.generate(x,43000) ;
03468
03469
03470 RooFitResult* r_ml_unw10 = p2.fitTo(*data2,Save()) ;
03471 RooFitResult* r_ml_unw43 = p2.fitTo(*data3,Save()) ;
03472
03473
03474
03475
03476
03477
03478 RooDataHist* binnedData = dataw.binnedClone() ;
03479
03480
03481
03482
03483
03484
03485 RooChi2Var chi2("chi2","chi2",p2,*binnedData,DataError(RooAbsData::SumW2)) ;
03486 RooMinuit m(chi2) ;
03487 m.migrad() ;
03488 m.hesse() ;
03489
03490
03491 RooFitResult* r_chi2_wgt = m.save() ;
03492 p2.plotOn(frame,LineStyle(kDashed),LineColor(kRed),Name("p2_alt")) ;
03493
03494
03495
03496
03497
03498
03499
03500
03501
03502
03503 regResult(r_ml_unw10,"rf403_ml_unw10") ;
03504 regResult(r_ml_unw43,"rf403_ml_unw43") ;
03505 regResult(r_ml_wgt ,"rf403_ml_wgt") ;
03506 regResult(r_chi2_wgt ,"rf403_ml_chi2") ;
03507 regPlot(frame,"rf403_plot1") ;
03508
03509 delete binnedData ;
03510 delete data ;
03511 delete data2 ;
03512 delete data3 ;
03513
03514 return kTRUE ;
03515 }
03516 } ;
03517
03518
03519
03520
03521
03522
03523
03524
03525
03526
03527
03528
03529 #ifndef __CINT__
03530 #include "RooGlobalFunc.h"
03531 #endif
03532 #include "RooRealVar.h"
03533 #include "RooDataSet.h"
03534 #include "RooPolynomial.h"
03535 #include "RooCategory.h"
03536 #include "Roo1DTable.h"
03537 #include "RooGaussian.h"
03538 #include "TCanvas.h"
03539 #include "RooPlot.h"
03540 using namespace RooFit ;
03541
03542
03543 class TestBasic404 : public RooFitTestUnit
03544 {
03545 public:
03546 TestBasic404(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Categories basic functionality",refFile,writeRef,verbose) {} ;
03547 Bool_t testCode() {
03548
03549
03550
03551
03552
03553 RooCategory tagCat("tagCat","Tagging category") ;
03554 tagCat.defineType("Lepton") ;
03555 tagCat.defineType("Kaon") ;
03556 tagCat.defineType("NetTagger-1") ;
03557 tagCat.defineType("NetTagger-2") ;
03558
03559
03560
03561
03562
03563
03564
03565 RooCategory b0flav("b0flav","B0 flavour eigenstate") ;
03566 b0flav.defineType("B0",-1) ;
03567 b0flav.defineType("B0bar",1) ;
03568
03569
03570
03571
03572
03573
03574
03575 RooRealVar x("x","x",0,10) ;
03576 RooDataSet *data = RooPolynomial("p","p",x).generate(RooArgSet(x,b0flav,tagCat),10000) ;
03577
03578
03579
03580
03581
03582
03583
03584 Roo1DTable* btable = data->table(b0flav) ;
03585
03586
03587 Roo1DTable* ttable = data->table(tagCat,"x>8.23") ;
03588
03589
03590 Roo1DTable* bttable = data->table(RooArgSet(tagCat,b0flav)) ;
03591
03592
03593
03594 Double_t nb0 = btable->get("B0") ;
03595 regValue(nb0,"rf404_nb0") ;
03596
03597
03598 Double_t fracLep = ttable->getFrac("Lepton") ;
03599 regValue(fracLep,"rf404_fracLep") ;
03600
03601
03602
03603
03604
03605
03606 tagCat.setRange("good","Lepton,Kaon") ;
03607
03608
03609 tagCat.addToRange("soso","NetTagger-1") ;
03610 tagCat.addToRange("soso","NetTagger-2") ;
03611
03612
03613 RooDataSet* goodData = (RooDataSet*) data->reduce(CutRange("good")) ;
03614 Roo1DTable* gtable = goodData->table(tagCat) ;
03615
03616
03617 regTable(btable,"rf404_btable") ;
03618 regTable(ttable,"rf404_ttable") ;
03619 regTable(bttable,"rf404_bttable") ;
03620 regTable(gtable,"rf404_gtable") ;
03621
03622
03623 delete goodData ;
03624 delete data ;
03625 return kTRUE ;
03626
03627 }
03628
03629 } ;
03630
03631
03632
03633
03634
03635
03636
03637
03638
03639
03640
03641
03642 #ifndef __CINT__
03643 #include "RooGlobalFunc.h"
03644 #endif
03645 #include "RooRealVar.h"
03646 #include "RooDataSet.h"
03647 #include "RooGaussian.h"
03648 #include "RooCategory.h"
03649 #include "RooThresholdCategory.h"
03650 #include "RooBinningCategory.h"
03651 #include "Roo1DTable.h"
03652 #include "RooArgusBG.h"
03653 #include "TCanvas.h"
03654 #include "RooPlot.h"
03655 #include "RooRealConstant.h"
03656 using namespace RooFit ;
03657
03658
03659 class TestBasic405 : public RooFitTestUnit
03660 {
03661 public:
03662 TestBasic405(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Real-to-category functions",refFile,writeRef,verbose) {} ;
03663 Bool_t testCode() {
03664
03665
03666
03667
03668
03669
03670
03671 RooRealVar x("x","x",0,10) ;
03672 RooArgusBG a("a","argus(x)",x,RooRealConstant::value(10),RooRealConstant::value(-1)) ;
03673
03674
03675 RooDataSet *data = a.generate(x,10000) ;
03676
03677
03678
03679
03680
03681
03682
03683
03684
03685
03686 RooThresholdCategory xRegion("xRegion","region of x",x,"Background") ;
03687
03688
03689
03690
03691
03692
03693
03694
03695 xRegion.addThreshold(4.23,"Background") ;
03696 xRegion.addThreshold(5.23,"SideBand") ;
03697 xRegion.addThreshold(8.23,"Signal") ;
03698 xRegion.addThreshold(9.23,"SideBand") ;
03699
03700
03701
03702
03703
03704
03705
03706 data->addColumn(xRegion) ;
03707
03708
03709 RooPlot* xframe = x.frame(Title("Demo of threshold and binning mapping functions")) ;
03710 data->plotOn(xframe) ;
03711
03712
03713 data->plotOn(xframe,Cut("xRegion==xRegion::SideBand"),MarkerColor(kRed),LineColor(kRed),Name("data_cut")) ;
03714
03715
03716
03717
03718
03719
03720
03721
03722
03723
03724
03725 x.setBins(10,"coarse") ;
03726 RooBinningCategory xBins("xBins","coarse bins in x",x,"coarse") ;
03727
03728
03729
03730
03731
03732
03733
03734
03735 Roo1DTable* xbtable = data->table(xBins) ;
03736
03737
03738 RooCategory* xb = (RooCategory*) data->addColumn(xBins) ;
03739
03740
03741 xb->setRange("alt","x_coarse_bin1,x_coarse_bin3,x_coarse_bin5,x_coarse_bin7,x_coarse_bin9") ;
03742
03743
03744 RooDataSet* dataSel = (RooDataSet*) data->reduce(CutRange("alt"),EventRange(0,5000)) ;
03745
03746
03747
03748 regTable(xbtable,"rf405_xbtable") ;
03749 regPlot(xframe,"rf405_plot1") ;
03750
03751 delete data ;
03752 delete dataSel ;
03753
03754 return kTRUE ;
03755
03756 }
03757
03758 } ;
03759
03760
03761
03762
03763
03764
03765
03766
03767
03768
03769
03770
03771 #ifndef __CINT__
03772 #include "RooGlobalFunc.h"
03773 #endif
03774 #include "RooRealVar.h"
03775 #include "RooDataSet.h"
03776 #include "RooPolynomial.h"
03777 #include "RooCategory.h"
03778 #include "RooMappedCategory.h"
03779 #include "RooMultiCategory.h"
03780 #include "RooSuperCategory.h"
03781 #include "Roo1DTable.h"
03782 #include "TCanvas.h"
03783 #include "RooPlot.h"
03784 using namespace RooFit ;
03785
03786
03787 class TestBasic406 : public RooFitTestUnit
03788 {
03789 public:
03790 TestBasic406(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Category-to-category functions",refFile,writeRef,verbose) {} ;
03791 Bool_t testCode() {
03792
03793
03794
03795
03796
03797 RooCategory tagCat("tagCat","Tagging category") ;
03798 tagCat.defineType("Lepton") ;
03799 tagCat.defineType("Kaon") ;
03800 tagCat.defineType("NetTagger-1") ;
03801 tagCat.defineType("NetTagger-2") ;
03802
03803
03804 RooCategory b0flav("b0flav","B0 flavour eigenstate") ;
03805 b0flav.defineType("B0",-1) ;
03806 b0flav.defineType("B0bar",1) ;
03807
03808
03809 RooRealVar x("x","x",0,10) ;
03810 RooPolynomial p("p","p",x) ;
03811 RooDataSet* data = p.generate(RooArgSet(x,b0flav,tagCat),10000) ;
03812
03813
03814
03815
03816
03817
03818
03819
03820
03821 RooMappedCategory tcatType("tcatType","tagCat type",tagCat,"Cut based") ;
03822
03823
03824 tcatType.map("Lepton","Cut based") ;
03825 tcatType.map("Kaon","Cut based") ;
03826
03827
03828 tcatType.map("NetTagger*","Neural Network") ;
03829
03830
03831 Roo1DTable* mtable = data->table(tcatType) ;
03832
03833
03834
03835
03836
03837
03838
03839
03840 RooSuperCategory b0Xtcat("b0Xtcat","b0flav X tagCat",RooArgSet(b0flav,tagCat)) ;
03841
03842
03843 Roo1DTable* stable = data->table(b0Xtcat) ;
03844
03845
03846 b0Xtcat.setLabel("{B0bar;Lepton}") ;
03847
03848
03849
03850
03851
03852 RooMultiCategory b0Xttype("b0Xttype","b0flav X tagType",RooArgSet(b0flav,tcatType)) ;
03853
03854
03855 Roo1DTable* xtable = data->table(b0Xttype) ;
03856
03857 regTable(mtable,"rf406_mtable") ;
03858 regTable(stable,"rf406_stable") ;
03859 regTable(xtable,"rf406_xtable") ;
03860
03861 delete data ;
03862
03863 return kTRUE ;
03864 }
03865
03866 } ;
03867
03868
03869
03870
03871
03872
03873
03874
03875
03876
03877
03878
03879
03880 #ifndef __CINT__
03881 #include "RooGlobalFunc.h"
03882 #endif
03883 #include "RooRealVar.h"
03884 #include "RooDataSet.h"
03885 #include "RooGaussian.h"
03886 #include "RooChebychev.h"
03887 #include "RooAddPdf.h"
03888 #include "RooSimultaneous.h"
03889 #include "RooCategory.h"
03890 #include "TCanvas.h"
03891 #include "RooPlot.h"
03892 using namespace RooFit ;
03893
03894
03895 class TestBasic501 : public RooFitTestUnit
03896 {
03897 public:
03898 TestBasic501(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Simultaneous p.d.f. operator",refFile,writeRef,verbose) {} ;
03899 Bool_t testCode() {
03900
03901
03902
03903
03904
03905 RooRealVar x("x","x",-8,8) ;
03906
03907
03908 RooRealVar mean("mean","mean",0,-8,8) ;
03909 RooRealVar sigma("sigma","sigma",0.3,0.1,10) ;
03910 RooGaussian gx("gx","gx",x,mean,sigma) ;
03911
03912
03913 RooRealVar a0("a0","a0",-0.1,-1,1) ;
03914 RooRealVar a1("a1","a1",0.004,-1,1) ;
03915 RooChebychev px("px","px",x,RooArgSet(a0,a1)) ;
03916
03917
03918 RooRealVar f("f","f",0.2,0.,1.) ;
03919 RooAddPdf model("model","model",RooArgList(gx,px),f) ;
03920
03921
03922
03923
03924
03925
03926
03927
03928 RooRealVar mean_ctl("mean_ctl","mean_ctl",-3,-8,8) ;
03929 RooGaussian gx_ctl("gx_ctl","gx_ctl",x,mean_ctl,sigma) ;
03930
03931
03932 RooRealVar a0_ctl("a0_ctl","a0_ctl",-0.1,-1,1) ;
03933 RooRealVar a1_ctl("a1_ctl","a1_ctl",0.5,-0.1,1) ;
03934 RooChebychev px_ctl("px_ctl","px_ctl",x,RooArgSet(a0_ctl,a1_ctl)) ;
03935
03936
03937 RooRealVar f_ctl("f_ctl","f_ctl",0.5,0.,1.) ;
03938 RooAddPdf model_ctl("model_ctl","model_ctl",RooArgList(gx_ctl,px_ctl),f_ctl) ;
03939
03940
03941
03942
03943
03944
03945
03946 RooDataSet *data = model.generate(RooArgSet(x),100) ;
03947 RooDataSet *data_ctl = model_ctl.generate(RooArgSet(x),2000) ;
03948
03949
03950
03951
03952
03953
03954
03955 RooCategory sample("sample","sample") ;
03956 sample.defineType("physics") ;
03957 sample.defineType("control") ;
03958
03959
03960 RooDataSet combData("combData","combined data",x,Index(sample),Import("physics",*data),Import("control",*data_ctl)) ;
03961
03962
03963
03964
03965
03966
03967
03968 RooSimultaneous simPdf("simPdf","simultaneous pdf",sample) ;
03969
03970
03971 simPdf.addPdf(model,"physics") ;
03972 simPdf.addPdf(model_ctl,"control") ;
03973
03974
03975
03976
03977
03978
03979
03980 simPdf.fitTo(combData) ;
03981
03982
03983
03984
03985
03986
03987
03988 RooPlot* frame1 = x.frame(Bins(30),Title("Physics sample")) ;
03989
03990
03991 combData.plotOn(frame1,Cut("sample==sample::physics")) ;
03992
03993
03994
03995
03996
03997 simPdf.plotOn(frame1,Slice(sample,"physics"),ProjWData(sample,combData)) ;
03998 simPdf.plotOn(frame1,Slice(sample,"physics"),Components("px"),ProjWData(sample,combData),LineStyle(kDashed)) ;
03999
04000
04001 RooPlot* frame2 = x.frame(Bins(30),Title("Control sample")) ;
04002 combData.plotOn(frame2,Cut("sample==sample::control")) ;
04003 simPdf.plotOn(frame2,Slice(sample,"control"),ProjWData(sample,combData)) ;
04004 simPdf.plotOn(frame2,Slice(sample,"control"),Components("px_ctl"),ProjWData(sample,combData),LineStyle(kDashed)) ;
04005
04006
04007 regPlot(frame1,"rf501_plot1") ;
04008 regPlot(frame2,"rf501_plot2") ;
04009
04010 delete data ;
04011 delete data_ctl ;
04012
04013 return kTRUE ;
04014
04015 }
04016
04017 } ;
04018
04019
04020
04021
04022
04023
04024
04025
04026
04027
04028
04029
04030
04031 #ifndef __CINT__
04032 #include "RooGlobalFunc.h"
04033 #endif
04034 #include "RooWorkspace.h"
04035 #include "RooProdPdf.h"
04036 #include "RooRealVar.h"
04037 #include "RooDataSet.h"
04038 #include "RooGaussian.h"
04039 #include "RooGaussModel.h"
04040 #include "RooAddModel.h"
04041 #include "RooDecay.h"
04042 #include "RooChebychev.h"
04043 #include "RooAddPdf.h"
04044 #include "RooSimultaneous.h"
04045 #include "RooCategory.h"
04046 #include "TCanvas.h"
04047 #include "RooPlot.h"
04048 using namespace RooFit ;
04049
04050
04051 class TestBasic599 : public RooFitTestUnit
04052 {
04053 public:
04054 TestBasic599(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Workspace and p.d.f. persistence",refFile,writeRef,verbose) {} ;
04055 Bool_t testCode() {
04056
04057 if (_write) {
04058
04059 RooWorkspace *w = new RooWorkspace("TestBasic11_ws") ;
04060
04061 regWS(w,"Basic11_ws") ;
04062
04063
04064 RooRealVar x("x","x",-10,10) ;
04065 RooRealVar meanx("meanx","mean of gaussian",-1) ;
04066 RooRealVar sigmax("sigmax","width of gaussian",3) ;
04067 RooGaussian gaussx("gaussx","gaussian PDF",x,meanx,sigmax) ;
04068
04069
04070 RooRealVar y("y","y",-10,10) ;
04071 RooRealVar meany("meany","mean of gaussian",-1) ;
04072 RooRealVar sigmay("sigmay","width of gaussian",3) ;
04073 RooGaussian gaussy("gaussy","gaussian PDF",y,meany,sigmay) ;
04074
04075
04076 RooProdPdf gaussxy("gaussxy","gaussx*gaussy",RooArgSet(gaussx,gaussy)) ;
04077
04078
04079 RooPolynomial flatx("flatx","flatx",x) ;
04080 RooPolynomial flaty("flaty","flaty",x) ;
04081 RooProdPdf flatxy("flatxy","flatx*flaty",RooArgSet(flatx,flaty)) ;
04082
04083
04084 RooRealVar frac("frac","frac",0.5,0.,1.) ;
04085 RooAddPdf sumxy("sumxy","sumxy",RooArgList(gaussxy,flatxy),frac) ;
04086
04087
04088 w->import(gaussx) ;
04089 w->import(gaussxy,RenameConflictNodes("set2")) ;
04090 w->import(sumxy,RenameConflictNodes("set3")) ;
04091
04092
04093 RooPlot* frame1 = x.frame() ;
04094 gaussx.plotOn(frame1) ;
04095 regPlot(frame1,"Basic11_gaussx_framex") ;
04096
04097
04098 RooPlot* frame2 = x.frame() ;
04099 gaussxy.plotOn(frame2) ;
04100 regPlot(frame2,"Basic11_gaussxy_framex") ;
04101
04102 RooPlot* frame3 = y.frame() ;
04103 gaussxy.plotOn(frame3) ;
04104 regPlot(frame3,"Basic11_gaussxy_framey") ;
04105
04106
04107 RooPlot* frame4 = x.frame() ;
04108 sumxy.plotOn(frame4) ;
04109 regPlot(frame4,"Basic11_sumxy_framex") ;
04110
04111 RooPlot* frame5 = y.frame() ;
04112 sumxy.plotOn(frame5) ;
04113 regPlot(frame5,"Basic11_sumxy_framey") ;
04114
04115
04116
04117
04118 RooRealVar dt("dt","dt",-20,20) ;
04119 RooRealVar tau("tau","tau",1.548) ;
04120
04121
04122 RooRealVar bias1("bias1","bias1",0) ;
04123 RooRealVar sigma1("sigma1","sigma1",1) ;
04124 RooGaussModel gm1("gm1","gauss model 1",dt,bias1,sigma1) ;
04125
04126
04127 RooDecay decay_gm1("decay_gm1","decay",dt,tau,gm1,RooDecay::DoubleSided) ;
04128
04129
04130 RooRealVar bias2("bias2","bias2",0) ;
04131 RooRealVar sigma2("sigma2","sigma2",5) ;
04132 RooGaussModel gm2("gm2","gauss model 2",dt,bias2,sigma2) ;
04133
04134
04135 RooRealVar gm1frac("gm1frac","fraction of gm1",0.5) ;
04136 RooAddModel gmsum("gmsum","sum of gm1 and gm2",RooArgList(gm1,gm2),gm1frac) ;
04137
04138
04139 RooDecay decay_gmsum("decay_gmsum","decay",dt,tau,gmsum,RooDecay::DoubleSided) ;
04140
04141 w->import(decay_gm1) ;
04142 w->import(decay_gmsum,RenameConflictNodes("set3")) ;
04143
04144 RooPlot* frame6 = dt.frame() ;
04145 decay_gm1.plotOn(frame6) ;
04146 regPlot(frame6,"Basic11_decay_gm1_framedt") ;
04147
04148 RooPlot* frame7 = dt.frame() ;
04149 decay_gmsum.plotOn(frame7) ;
04150 regPlot(frame7,"Basic11_decay_gmsum_framedt") ;
04151
04152
04153 RooCategory cat("cat","cat") ;
04154 cat.defineType("A") ;
04155 cat.defineType("B") ;
04156 RooSimultaneous sim("sim","sim",cat) ;
04157 sim.addPdf(gaussxy,"A") ;
04158 sim.addPdf(flatxy,"B") ;
04159
04160 w->import(sim,RenameConflictNodes("set4")) ;
04161
04162
04163 RooDataHist dh("dh","dh",cat) ;
04164 cat.setLabel("A") ;
04165 dh.add(cat) ;
04166 cat.setLabel("B") ;
04167 dh.add(cat) ;
04168
04169 RooPlot* frame8 = x.frame() ;
04170 sim.plotOn(frame8,ProjWData(cat,dh),Project(cat)) ;
04171
04172 regPlot(frame8,"Basic11_sim_framex") ;
04173
04174
04175 } else {
04176
04177 RooWorkspace* w = getWS("Basic11_ws") ;
04178 if (!w) return kFALSE ;
04179
04180
04181 RooAbsPdf* gaussx = w->pdf("gaussx") ;
04182
04183
04184 RooPlot* frame1 = w->var("x")->frame() ;
04185 gaussx->plotOn(frame1) ;
04186 regPlot(frame1,"Basic11_gaussx_framex") ;
04187
04188
04189 RooAbsPdf* gaussxy = w->pdf("gaussxy") ;
04190
04191
04192 RooPlot* frame2 = w->var("x")->frame() ;
04193 gaussxy->plotOn(frame2) ;
04194 regPlot(frame2,"Basic11_gaussxy_framex") ;
04195
04196
04197 RooPlot* frame3 = w->var("y")->frame() ;
04198 gaussxy->plotOn(frame3) ;
04199 regPlot(frame3,"Basic11_gaussxy_framey") ;
04200
04201
04202 RooAbsPdf* sumxy = w->pdf("sumxy") ;
04203
04204
04205 RooPlot* frame4 = w->var("x")->frame() ;
04206 sumxy->plotOn(frame4) ;
04207 regPlot(frame4,"Basic11_sumxy_framex") ;
04208
04209
04210 RooPlot* frame5 = w->var("y")->frame() ;
04211 sumxy->plotOn(frame5) ;
04212 regPlot(frame5,"Basic11_sumxy_framey") ;
04213
04214
04215 RooAbsPdf* decay_gm1 = w->pdf("decay_gm1") ;
04216
04217
04218 RooPlot* frame6 = w->var("dt")->frame() ;
04219 decay_gm1->plotOn(frame6) ;
04220 regPlot(frame6,"Basic11_decay_gm1_framedt") ;
04221
04222
04223 RooAbsPdf* decay_gmsum = w->pdf("decay_gmsum") ;
04224
04225
04226 RooPlot* frame7 = w->var("dt")->frame() ;
04227 decay_gmsum->plotOn(frame7) ;
04228 regPlot(frame7,"Basic11_decay_gmsum_framedt") ;
04229
04230
04231 RooAbsPdf* sim = w->pdf("sim") ;
04232 RooCategory* cat = w->cat("cat") ;
04233
04234
04235 RooPlot* frame8 = w->var("x")->frame() ;
04236
04237 RooDataHist dh("dh","dh",*cat) ;
04238 cat->setLabel("A") ;
04239 dh.add(*cat) ;
04240 cat->setLabel("B") ;
04241 dh.add(*cat) ;
04242
04243 sim->plotOn(frame8,ProjWData(*cat,dh),Project(*cat)) ;
04244
04245 regPlot(frame8,"Basic11_sim_framex") ;
04246
04247 }
04248
04249
04250 return kTRUE ;
04251 }
04252 } ;
04253
04254
04255
04256
04257
04258
04259
04260
04261
04262
04263
04264 #ifndef __CINT__
04265 #include "RooGlobalFunc.h"
04266 #endif
04267 #include "RooRealVar.h"
04268 #include "RooDataSet.h"
04269 #include "RooGaussian.h"
04270 #include "RooProdPdf.h"
04271 #include "RooAddPdf.h"
04272 #include "RooMinuit.h"
04273 #include "RooNLLVar.h"
04274 #include "RooFitResult.h"
04275 #include "RooPlot.h"
04276 #include "TCanvas.h"
04277 #include "TH1.h"
04278 using namespace RooFit ;
04279
04280
04281 class TestBasic601 : public RooFitTestUnit
04282 {
04283 public:
04284 TestBasic601(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Interactive Minuit",refFile,writeRef,verbose) {} ;
04285 Bool_t testCode() {
04286
04287
04288
04289
04290
04291 RooRealVar x("x","x",-20,20) ;
04292
04293
04294 RooRealVar mean("mean","mean of g1 and g2",0) ;
04295 RooRealVar sigma_g1("sigma_g1","width of g1",3) ;
04296 RooGaussian g1("g1","g1",x,mean,sigma_g1) ;
04297
04298 RooRealVar sigma_g2("sigma_g2","width of g2",4,3.0,6.0) ;
04299 RooGaussian g2("g2","g2",x,mean,sigma_g2) ;
04300
04301 RooRealVar frac("frac","frac",0.5,0.0,1.0) ;
04302 RooAddPdf model("model","model",RooArgList(g1,g2),frac) ;
04303
04304
04305 RooDataSet* data = model.generate(x,1000) ;
04306
04307
04308 RooNLLVar nll("nll","nll",model,*data) ;
04309
04310
04311
04312
04313
04314
04315 RooMinuit m(nll) ;
04316
04317
04318 m.migrad() ;
04319
04320
04321 m.hesse() ;
04322
04323
04324 m.minos(sigma_g2) ;
04325
04326
04327
04328
04329
04330
04331
04332
04333
04334
04335 RooFitResult* r = m.save() ;
04336
04337
04338
04339
04340
04341
04342
04343 mean = 0.3 ;
04344
04345
04346 m.migrad() ;
04347 m.hesse() ;
04348
04349
04350 sigma_g2.setConstant(kTRUE) ;
04351
04352
04353 m.migrad() ;
04354 m.hesse() ;
04355
04356 RooFitResult* r2 = m.save() ;
04357
04358 regResult(r,"rf601_r") ;
04359 regResult(r2,"rf601_r2") ;
04360
04361 delete data ;
04362
04363 return kTRUE ;
04364 }
04365 } ;
04366
04367
04368
04369
04370
04371
04372
04373
04374
04375
04376
04377
04378 #ifndef __CINT__
04379 #include "RooGlobalFunc.h"
04380 #endif
04381 #include "RooRealVar.h"
04382 #include "RooDataSet.h"
04383 #include "RooGaussian.h"
04384 #include "RooChebychev.h"
04385 #include "RooAddPdf.h"
04386 #include "RooChi2Var.h"
04387 #include "RooMinuit.h"
04388 #include "TCanvas.h"
04389 #include "RooPlot.h"
04390 using namespace RooFit ;
04391
04392
04393 class TestBasic602 : public RooFitTestUnit
04394 {
04395 public:
04396 TestBasic602(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Chi2 minimization",refFile,writeRef,verbose) {} ;
04397 Bool_t testCode() {
04398
04399
04400
04401
04402
04403 RooRealVar x("x","x",0,10) ;
04404
04405
04406 RooRealVar mean("mean","mean of gaussians",5) ;
04407 RooRealVar sigma1("sigma1","width of gaussians",0.5) ;
04408 RooRealVar sigma2("sigma2","width of gaussians",1) ;
04409
04410 RooGaussian sig1("sig1","Signal component 1",x,mean,sigma1) ;
04411 RooGaussian sig2("sig2","Signal component 2",x,mean,sigma2) ;
04412
04413
04414 RooRealVar a0("a0","a0",0.5,0.,1.) ;
04415 RooRealVar a1("a1","a1",-0.2,0.,1.) ;
04416 RooChebychev bkg("bkg","Background",x,RooArgSet(a0,a1)) ;
04417
04418
04419 RooRealVar sig1frac("sig1frac","fraction of component 1 in signal",0.8,0.,1.) ;
04420 RooAddPdf sig("sig","Signal",RooArgList(sig1,sig2),sig1frac) ;
04421
04422
04423 RooRealVar bkgfrac("bkgfrac","fraction of background",0.5,0.,1.) ;
04424 RooAddPdf model("model","g1+g2+a",RooArgList(bkg,sig),bkgfrac) ;
04425
04426
04427
04428
04429
04430 RooDataSet* d = model.generate(x,10000) ;
04431 RooDataHist* dh = d->binnedClone() ;
04432
04433
04434
04435
04436
04437 RooChi2Var chi2("chi2","chi2",model,*dh) ;
04438
04439
04440 RooMinuit m(chi2) ;
04441 m.migrad() ;
04442 m.hesse() ;
04443
04444 RooFitResult* r = m.save() ;
04445
04446 regResult(r,"rf602_r") ;
04447
04448 delete d ;
04449 delete dh ;
04450
04451 return kTRUE ;
04452 }
04453 } ;
04454
04455
04456
04457
04458
04459
04460
04461
04462
04463
04464
04465 #ifndef __CINT__
04466 #include "RooGlobalFunc.h"
04467 #endif
04468 #include "RooRealVar.h"
04469 #include "RooDataSet.h"
04470 #include "RooGaussian.h"
04471 #include "RooPolynomial.h"
04472 #include "RooAddPdf.h"
04473 #include "RooProdPdf.h"
04474 #include "RooFitResult.h"
04475 #include "RooPlot.h"
04476 #include "TCanvas.h"
04477 #include "TH1.h"
04478 using namespace RooFit ;
04479
04480
04481 class TestBasic604 : public RooFitTestUnit
04482 {
04483 public:
04484 TestBasic604(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Auxiliary observable constraints",refFile,writeRef,verbose) {} ;
04485 Bool_t testCode() {
04486
04487
04488
04489
04490
04491 RooRealVar x("x","x",-10,10) ;
04492
04493 RooRealVar m("m","m",0,-10,10) ;
04494 RooRealVar s("s","s",2,0.1,10) ;
04495 RooGaussian gauss("gauss","gauss(x,m,s)",x,m,s) ;
04496
04497
04498 RooPolynomial poly("poly","poly(x)",x) ;
04499
04500
04501 RooRealVar f("f","f",0.5,0.,1.) ;
04502 RooAddPdf model("model","model",RooArgSet(gauss,poly),f) ;
04503
04504
04505 RooDataSet* d = model.generate(x,50) ;
04506
04507
04508
04509
04510
04511
04512
04513 RooGaussian fconstraint("fconstraint","fconstraint",f,RooConst(0.8),RooConst(0.1)) ;
04514
04515
04516
04517
04518
04519
04520
04521
04522
04523
04524 RooProdPdf modelc("modelc","model with constraint",RooArgSet(model,fconstraint)) ;
04525
04526
04527 RooFitResult* r1 = modelc.fitTo(*d,Save()) ;
04528
04529
04530 RooFitResult* r2 = modelc.fitTo(*d,Constrain(f),Save()) ;
04531
04532
04533
04534
04535
04536
04537
04538 RooGaussian fconstext("fconstext","fconstext",f,RooConst(0.2),RooConst(0.1)) ;
04539
04540
04541 RooFitResult* r3 = model.fitTo(*d,ExternalConstraints(fconstext),Save()) ;
04542
04543
04544 regResult(r1,"rf604_r1") ;
04545 regResult(r2,"rf604_r2") ;
04546 regResult(r3,"rf604_r3") ;
04547
04548 delete d ;
04549
04550 return kTRUE ;
04551 }
04552 } ;
04553
04554
04555
04556
04557
04558
04559
04560
04561
04562
04563
04564
04565 #ifndef __CINT__
04566 #include "RooGlobalFunc.h"
04567 #endif
04568 #include "RooRealVar.h"
04569 #include "RooDataSet.h"
04570 #include "RooGaussian.h"
04571 #include "RooAddPdf.h"
04572 #include "RooNLLVar.h"
04573 #include "RooProfileLL.h"
04574 #include "RooMinuit.h"
04575 #include "TCanvas.h"
04576 #include "RooPlot.h"
04577 using namespace RooFit ;
04578
04579
04580 class TestBasic605 : public RooFitTestUnit
04581 {
04582 public:
04583 TestBasic605(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Profile Likelihood operator",refFile,writeRef,verbose) {} ;
04584 Bool_t testCode() {
04585
04586
04587
04588
04589
04590 RooRealVar x("x","x",-20,20) ;
04591
04592
04593 RooRealVar mean("mean","mean of g1 and g2",0,-10,10) ;
04594 RooRealVar sigma_g1("sigma_g1","width of g1",3) ;
04595 RooGaussian g1("g1","g1",x,mean,sigma_g1) ;
04596
04597 RooRealVar sigma_g2("sigma_g2","width of g2",4,3.0,6.0) ;
04598 RooGaussian g2("g2","g2",x,mean,sigma_g2) ;
04599
04600 RooRealVar frac("frac","frac",0.5,0.0,1.0) ;
04601 RooAddPdf model("model","model",RooArgList(g1,g2),frac) ;
04602
04603
04604 RooDataSet* data = model.generate(x,1000) ;
04605
04606
04607
04608
04609
04610
04611
04612 RooNLLVar nll("nll","nll",model,*data) ;
04613
04614
04615 RooMinuit(nll).migrad() ;
04616
04617
04618 RooPlot* frame1 = frac.frame(Bins(10),Range(0.01,0.95),Title("LL and profileLL in frac")) ;
04619 nll.plotOn(frame1,ShiftToZero()) ;
04620
04621
04622 RooPlot* frame2 = sigma_g2.frame(Bins(10),Range(3.3,5.0),Title("LL and profileLL in sigma_g2")) ;
04623 nll.plotOn(frame2,ShiftToZero()) ;
04624
04625
04626
04627
04628
04629
04630
04631
04632 RooProfileLL pll_frac("pll_frac","pll_frac",nll,frac) ;
04633
04634
04635 pll_frac.plotOn(frame1,LineColor(kRed)) ;
04636
04637
04638 frame1->SetMinimum(0) ;
04639 frame1->SetMaximum(3) ;
04640
04641
04642
04643
04644
04645
04646
04647
04648 RooProfileLL pll_sigmag2("pll_sigmag2","pll_sigmag2",nll,sigma_g2) ;
04649
04650
04651 pll_sigmag2.plotOn(frame2,LineColor(kRed)) ;
04652
04653
04654 frame2->SetMinimum(0) ;
04655 frame2->SetMaximum(3) ;
04656
04657
04658 regPlot(frame1,"rf605_plot1") ;
04659 regPlot(frame2,"rf605_plot2") ;
04660
04661 delete data ;
04662
04663 return kTRUE ;
04664 }
04665 } ;
04666
04667
04668
04669
04670
04671
04672
04673
04674
04675
04676
04677
04678
04679 #ifndef __CINT__
04680 #include "RooGlobalFunc.h"
04681 #endif
04682 #include "RooRealVar.h"
04683 #include "RooDataSet.h"
04684 #include "RooArgusBG.h"
04685 #include "RooNLLVar.h"
04686 #include "TCanvas.h"
04687 #include "RooPlot.h"
04688 using namespace RooFit ;
04689
04690
04691 class TestBasic606 : public RooFitTestUnit
04692 {
04693 public:
04694 TestBasic606(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("NLL error handling",refFile,writeRef,verbose) {} ;
04695 Bool_t testCode() {
04696
04697
04698
04699
04700
04701 RooRealVar m("m","m",5.20,5.30) ;
04702
04703
04704 RooRealVar m0("m0","m0",5.291,5.20,5.30) ;
04705 RooRealVar k("k","k",-30,-50,-10) ;
04706
04707
04708 RooArgusBG argus("argus","argus",m,m0,k) ;
04709
04710
04711 RooDataSet* data = argus.generate(m,1000) ;
04712
04713
04714
04715
04716
04717
04718 RooPlot* frame1 = m.frame(Bins(40),Title("Argus model and data")) ;
04719 data->plotOn(frame1) ;
04720 argus.plotOn(frame1) ;
04721
04722
04723
04724
04725
04726
04727 argus.fitTo(*data,PrintEvalErrors(10),Warnings(kFALSE)) ;
04728 m0.setError(0.1) ;
04729 argus.fitTo(*data,PrintEvalErrors(0),EvalErrorWall(kFALSE),Warnings(kFALSE)) ;
04730
04731
04732
04733
04734
04735
04736
04737 RooNLLVar nll("nll","nll",argus,*data) ;
04738
04739
04740
04741
04742
04743
04744
04745
04746 RooPlot* frame2 = m0.frame(Range(5.288,5.293),Title("-log(L) scan vs m0")) ;
04747 nll.plotOn(frame2,PrintEvalErrors(0),ShiftToZero(),LineColor(kRed),Precision(1e-4)) ;
04748
04749
04750
04751
04752
04753
04754
04755 RooPlot* frame3 = m0.frame(Range(5.288,5.293),Title("-log(L) scan vs m0, problematic regions masked")) ;
04756 nll.plotOn(frame3,PrintEvalErrors(-1),ShiftToZero(),EvalErrorValue(nll.getVal()+10),LineColor(kRed)) ;
04757
04758
04759 regPlot(frame1,"rf606_plot1") ;
04760 regPlot(frame2,"rf606_plot2") ;
04761 regPlot(frame3,"rf606_plot3") ;
04762
04763 delete data ;
04764 return kTRUE ;
04765
04766 }
04767 } ;
04768
04769
04770
04771
04772
04773
04774
04775
04776
04777
04778
04779
04780 #ifndef __CINT__
04781 #include "RooGlobalFunc.h"
04782 #endif
04783 #include "RooRealVar.h"
04784 #include "RooDataSet.h"
04785 #include "RooGaussian.h"
04786 #include "RooAddPdf.h"
04787 #include "RooChebychev.h"
04788 #include "RooFitResult.h"
04789 #include "TCanvas.h"
04790 #include "RooPlot.h"
04791 #include "TFile.h"
04792 #include "TStyle.h"
04793 #include "TH2.h"
04794
04795 using namespace RooFit ;
04796
04797
04798 class TestBasic607 : public RooFitTestUnit
04799 {
04800 public:
04801 TestBasic607(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Fit Result functionality",refFile,writeRef,verbose) {} ;
04802 Bool_t testCode() {
04803
04804
04805
04806
04807
04808 RooRealVar x("x","x",0,10) ;
04809
04810
04811 RooRealVar mean("mean","mean of gaussians",5,-10,10) ;
04812 RooRealVar sigma1("sigma1","width of gaussians",0.5,0.1,10) ;
04813 RooRealVar sigma2("sigma2","width of gaussians",1,0.1,10) ;
04814
04815 RooGaussian sig1("sig1","Signal component 1",x,mean,sigma1) ;
04816 RooGaussian sig2("sig2","Signal component 2",x,mean,sigma2) ;
04817
04818
04819 RooRealVar a0("a0","a0",0.5,0.,1.) ;
04820 RooRealVar a1("a1","a1",-0.2) ;
04821 RooChebychev bkg("bkg","Background",x,RooArgSet(a0,a1)) ;
04822
04823
04824 RooRealVar sig1frac("sig1frac","fraction of component 1 in signal",0.8,0.,1.) ;
04825 RooAddPdf sig("sig","Signal",RooArgList(sig1,sig2),sig1frac) ;
04826
04827
04828 RooRealVar bkgfrac("bkgfrac","fraction of background",0.5,0.,1.) ;
04829 RooAddPdf model("model","g1+g2+a",RooArgList(bkg,sig),bkgfrac) ;
04830
04831
04832 RooDataSet* data = model.generate(x,1000) ;
04833
04834
04835
04836
04837
04838
04839
04840 RooFitResult* r = model.fitTo(*data,Save()) ;
04841
04842
04843
04844
04845
04846
04847 gStyle->SetOptStat(0) ;
04848 gStyle->SetPalette(1) ;
04849 TH2* hcorr = r->correlationHist() ;
04850
04851
04852
04853
04854 RooDataSet randPars("randPars","randPars",r->floatParsFinal()) ;
04855 for (Int_t i=0 ; i<10000 ; i++) {
04856 randPars.add(r->randomizePars()) ;
04857 }
04858
04859
04860 TH1* hhrand = randPars.createHistogram("hhrand",sigma1,Binning(35,0.25,0.65),YVar(sig1frac,Binning(35,0.3,1.1))) ;
04861
04862 regTH(hcorr,"rf607_hcorr") ;
04863 regTH(hhrand,"rf607_hhand") ;
04864
04865 delete data ;
04866 delete r ;
04867
04868 return kTRUE ;
04869
04870 }
04871 } ;
04872
04873
04874
04875
04876
04877
04878
04879
04880
04881
04882
04883
04884
04885
04886
04887
04888 #ifndef __CINT__
04889 #include "RooGlobalFunc.h"
04890 #endif
04891 #include "RooRealVar.h"
04892 #include "RooDataSet.h"
04893 #include "RooPolyVar.h"
04894 #include "RooChi2Var.h"
04895 #include "RooMinuit.h"
04896 #include "TCanvas.h"
04897 #include "RooPlot.h"
04898 #include "TRandom.h"
04899
04900 using namespace RooFit ;
04901
04902 class TestBasic609 : public RooFitTestUnit
04903 {
04904 public:
04905 TestBasic609(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Chi^2 fit to X-Y dataset",refFile,writeRef,verbose) {} ;
04906 Bool_t testCode() {
04907
04908
04909
04910
04911
04912
04913
04914
04915
04916
04917
04918 RooRealVar x("x","x",-11,11) ;
04919 RooRealVar y("y","y",-10,200) ;
04920 RooDataSet dxy("dxy","dxy",RooArgSet(x,y),StoreError(RooArgSet(x,y))) ;
04921
04922
04923 for (int i=0 ; i<=10 ; i++) {
04924
04925
04926 x = -10 + 2*i;
04927 x.setError( i<5 ? 0.5/1. : 1.0/1. ) ;
04928
04929
04930 y = x.getVal() * x.getVal() + 4*fabs(RooRandom::randomGenerator()->Gaus()) ;
04931 y.setError(sqrt(y.getVal())) ;
04932
04933 dxy.add(RooArgSet(x,y)) ;
04934 }
04935
04936
04937
04938
04939
04940
04941
04942 RooRealVar a("a","a",0.0,-10,10) ;
04943 RooRealVar b("b","b",0.0,-100,100) ;
04944 RooPolyVar f("f","f",x,RooArgList(b,a,RooConst(1))) ;
04945
04946
04947 RooPlot* frame = x.frame(Title("Chi^2 fit of function set of (X#pmdX,Y#pmdY) values")) ;
04948 dxy.plotOnXY(frame,YVar(y)) ;
04949
04950
04951 f.chi2FitTo(dxy,YVar(y)) ;
04952
04953
04954 f.plotOn(frame) ;
04955
04956
04957
04958 f.chi2FitTo(dxy,YVar(y),Integrate(kTRUE)) ;
04959
04960
04961 f.plotOn(frame,LineStyle(kDashed),LineColor(kRed),Name("alternate")) ;
04962
04963 regPlot(frame,"rf609_frame") ;
04964
04965 return kTRUE ;
04966 }
04967 } ;
04968
04969
04970
04971
04972
04973
04974
04975
04976
04977
04978
04979
04980
04981
04982
04983 #ifndef __CINT__
04984 #include "RooGlobalFunc.h"
04985 #endif
04986 #include "RooRealVar.h"
04987 #include "RooDataSet.h"
04988 #include "RooGaussian.h"
04989 #include "RooFormulaVar.h"
04990 #include "RooProdPdf.h"
04991 #include "RooEfficiency.h"
04992 #include "RooPolynomial.h"
04993 #include "RooCategory.h"
04994 #include "TCanvas.h"
04995 #include "RooPlot.h"
04996 using namespace RooFit ;
04997
04998
04999
05000 class TestBasic701 : public RooFitTestUnit
05001 {
05002 public:
05003 TestBasic701(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Efficiency operator p.d.f. 1D",refFile,writeRef,verbose) {} ;
05004 Bool_t testCode() {
05005
05006
05007
05008
05009
05010 RooRealVar x("x","x",-10,10) ;
05011
05012
05013 RooRealVar a("a","a",0.4,0,1) ;
05014 RooRealVar b("b","b",5) ;
05015 RooRealVar c("c","c",-1,-10,10) ;
05016 RooFormulaVar effFunc("effFunc","(1-a)+a*cos((x-c)/b)",RooArgList(a,b,c,x)) ;
05017
05018
05019
05020
05021
05022
05023
05024 RooCategory cut("cut","cutr") ;
05025 cut.defineType("accept",1) ;
05026 cut.defineType("reject",0) ;
05027
05028
05029 RooEfficiency effPdf("effPdf","effPdf",effFunc,cut,"accept") ;
05030
05031
05032
05033
05034
05035
05036
05037
05038 RooPolynomial shapePdf("shapePdf","shapePdf",x,RooConst(-0.095)) ;
05039 RooProdPdf model("model","model",shapePdf,Conditional(effPdf,cut)) ;
05040
05041
05042 RooDataSet* data = model.generate(RooArgSet(x,cut),10000) ;
05043
05044
05045
05046
05047
05048
05049
05050 effPdf.fitTo(*data,ConditionalObservables(x)) ;
05051
05052
05053
05054
05055
05056
05057
05058 RooPlot* frame1 = x.frame(Bins(20),Title("Data (all, accepted)")) ;
05059 data->plotOn(frame1) ;
05060 data->plotOn(frame1,Cut("cut==cut::accept"),MarkerColor(kRed),LineColor(kRed)) ;
05061
05062
05063 RooPlot* frame2 = x.frame(Bins(20),Title("Fitted efficiency")) ;
05064 data->plotOn(frame2,Efficiency(cut)) ;
05065 effFunc.plotOn(frame2,LineColor(kRed)) ;
05066
05067
05068 regPlot(frame1,"rf701_plot1") ;
05069 regPlot(frame2,"rf701_plot2") ;
05070
05071
05072 delete data ;
05073
05074 return kTRUE ;
05075 }
05076 } ;
05077
05078
05079
05080
05081
05082
05083
05084
05085
05086
05087
05088 #ifndef __CINT__
05089 #include "RooGlobalFunc.h"
05090 #endif
05091 #include "RooRealVar.h"
05092 #include "RooDataSet.h"
05093 #include "RooGaussian.h"
05094 #include "RooCategory.h"
05095 #include "RooEfficiency.h"
05096 #include "RooPolynomial.h"
05097 #include "RooProdPdf.h"
05098 #include "RooFormulaVar.h"
05099 #include "TCanvas.h"
05100 #include "TH1.h"
05101 #include "RooPlot.h"
05102 using namespace RooFit ;
05103
05104
05105
05106 class TestBasic702 : public RooFitTestUnit
05107 {
05108 public:
05109 TestBasic702(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Efficiency operator p.d.f. 2D",refFile,writeRef,verbose) {} ;
05110 Bool_t testCode() {
05111
05112 Bool_t flat=kFALSE ;
05113
05114
05115
05116
05117
05118 RooRealVar x("x","x",-10,10) ;
05119 RooRealVar y("y","y",-10,10) ;
05120
05121
05122 RooRealVar ax("ax","ay",0.6,0,1) ;
05123 RooRealVar bx("bx","by",5) ;
05124 RooRealVar cx("cx","cy",-1,-10,10) ;
05125
05126 RooRealVar ay("ay","ay",0.2,0,1) ;
05127 RooRealVar by("by","by",5) ;
05128 RooRealVar cy("cy","cy",-1,-10,10) ;
05129
05130 RooFormulaVar effFunc("effFunc","((1-ax)+ax*cos((x-cx)/bx))*((1-ay)+ay*cos((y-cy)/by))",RooArgList(ax,bx,cx,x,ay,by,cy,y)) ;
05131
05132
05133 RooCategory cut("cut","cutr") ;
05134 cut.defineType("accept",1) ;
05135 cut.defineType("reject",0) ;
05136
05137
05138
05139
05140
05141
05142
05143 RooEfficiency effPdf("effPdf","effPdf",effFunc,cut,"accept") ;
05144
05145
05146
05147
05148
05149
05150
05151
05152 RooPolynomial shapePdfX("shapePdfX","shapePdfX",x,RooConst(flat?0:-0.095)) ;
05153 RooPolynomial shapePdfY("shapePdfY","shapePdfY",y,RooConst(flat?0:+0.095)) ;
05154 RooProdPdf shapePdf("shapePdf","shapePdf",RooArgSet(shapePdfX,shapePdfY)) ;
05155 RooProdPdf model("model","model",shapePdf,Conditional(effPdf,cut)) ;
05156
05157
05158 RooDataSet* data = model.generate(RooArgSet(x,y,cut),10000) ;
05159
05160
05161
05162
05163
05164
05165
05166 effPdf.fitTo(*data,ConditionalObservables(RooArgSet(x,y))) ;
05167
05168
05169
05170
05171
05172
05173
05174 TH1* hh_data_all = data->createHistogram("hh_data_all",x,Binning(8),YVar(y,Binning(8))) ;
05175 TH1* hh_data_sel = data->createHistogram("hh_data_sel",x,Binning(8),YVar(y,Binning(8)),Cut("cut==cut::accept")) ;
05176 TH1* hh_eff = effFunc.createHistogram("hh_eff",x,Binning(50),YVar(y,Binning(50))) ;
05177
05178
05179 hh_data_all->SetMinimum(0) ;
05180 hh_data_sel->SetMinimum(0) ;
05181 hh_eff->SetMinimum(0) ;
05182 hh_eff->SetLineColor(kBlue) ;
05183
05184 regTH(hh_data_all,"rf702_hh_data_all") ;
05185 regTH(hh_data_sel,"rf702_hh_data_sel") ;
05186 regTH(hh_eff,"rf702_hh_eff") ;
05187
05188 delete data ;
05189
05190 return kTRUE;
05191
05192 }
05193 } ;
05194
05195
05196
05197
05198
05199
05200
05201
05202
05203
05204
05205
05206 #ifndef __CINT__
05207 #include "RooGlobalFunc.h"
05208 #endif
05209 #include "RooRealVar.h"
05210 #include "RooDataSet.h"
05211 #include "RooGaussian.h"
05212 #include "RooExponential.h"
05213 #include "RooEffProd.h"
05214 #include "RooFormulaVar.h"
05215 #include "TCanvas.h"
05216 #include "RooPlot.h"
05217 using namespace RooFit ;
05218
05219
05220
05221 class TestBasic703 : public RooFitTestUnit
05222 {
05223 public:
05224 TestBasic703(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Efficiency product operator p.d.f",refFile,writeRef,verbose) {} ;
05225 Bool_t testCode() {
05226
05227
05228
05229
05230
05231 RooRealVar t("t","t",0,5) ;
05232
05233
05234 RooRealVar tau("tau","tau",-1.54,-4,-0.1) ;
05235 RooExponential model("model","model",t,tau) ;
05236
05237
05238
05239
05240
05241
05242
05243 RooFormulaVar eff("eff","0.5*(TMath::Erf((t-1)/0.5)+1)",t) ;
05244
05245
05246
05247
05248
05249
05250
05251 RooEffProd modelEff("modelEff","model with efficiency",model,eff) ;
05252
05253
05254
05255
05256
05257
05258 RooPlot* frame1 = t.frame(Title("Efficiency")) ;
05259 eff.plotOn(frame1,LineColor(kRed)) ;
05260
05261 RooPlot* frame2 = t.frame(Title("Pdf with and without efficiency")) ;
05262
05263 model.plotOn(frame2,LineStyle(kDashed)) ;
05264 modelEff.plotOn(frame2) ;
05265
05266
05267
05268
05269
05270
05271
05272
05273 RooDataSet* data = modelEff.generate(t,10000) ;
05274
05275
05276 modelEff.fitTo(*data) ;
05277
05278
05279 RooPlot* frame3 = t.frame(Title("Fitted pdf with efficiency")) ;
05280 data->plotOn(frame3) ;
05281 modelEff.plotOn(frame3) ;
05282
05283
05284 regPlot(frame1,"rf703_plot1") ;
05285 regPlot(frame2,"rf703_plot2") ;
05286 regPlot(frame3,"rf703_plot3") ;
05287
05288
05289 delete data ;
05290 return kTRUE ;
05291 }
05292 } ;
05293
05294
05295
05296
05297
05298
05299
05300
05301
05302
05303
05304
05305 #ifndef __CINT__
05306 #include "RooGlobalFunc.h"
05307 #endif
05308 #include "RooRealVar.h"
05309 #include "RooDataSet.h"
05310 #include "RooGaussian.h"
05311 #include "RooTruthModel.h"
05312 #include "RooFormulaVar.h"
05313 #include "RooRealSumPdf.h"
05314 #include "RooPolyVar.h"
05315 #include "RooProduct.h"
05316 #include "TH1.h"
05317 #include "TCanvas.h"
05318 #include "RooPlot.h"
05319 using namespace RooFit ;
05320
05321
05322
05323 class TestBasic704 : public RooFitTestUnit
05324 {
05325 public:
05326 TestBasic704(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Amplitude sum operator p.d.f",refFile,writeRef,verbose) {} ;
05327 Bool_t testCode() {
05328
05329
05330
05331
05332
05333 RooRealVar t("t","time",-1.,15.);
05334 RooRealVar cosa("cosa","cos(alpha)",-1.,1.);
05335
05336
05337 RooRealVar tau("tau","#tau",1.5);
05338 RooRealVar deltaGamma("deltaGamma","deltaGamma", 0.3);
05339 RooTruthModel tm("tm","tm",t) ;
05340 RooFormulaVar coshGBasis("coshGBasis","exp(-@0/ @1)*cosh(@0*@2/2)",RooArgList(t,tau,deltaGamma));
05341 RooFormulaVar sinhGBasis("sinhGBasis","exp(-@0/ @1)*sinh(@0*@2/2)",RooArgList(t,tau,deltaGamma));
05342 RooAbsReal* coshGConv = tm.convolution(&coshGBasis,&t);
05343 RooAbsReal* sinhGConv = tm.convolution(&sinhGBasis,&t);
05344
05345
05346 RooPolyVar poly1("poly1","poly1",cosa,RooArgList(RooConst(0.5),RooConst(0.2),RooConst(0.2)),0);
05347 RooPolyVar poly2("poly2","poly2",cosa,RooArgList(RooConst(1),RooConst(-0.2),RooConst(3)),0);
05348
05349
05350 RooProduct ampl1("ampl1","amplitude 1",RooArgSet(poly1,*coshGConv));
05351 RooProduct ampl2("ampl2","amplitude 2",RooArgSet(poly2,*sinhGConv));
05352
05353
05354
05355
05356
05357
05358
05359 RooRealVar f1("f1","f1",1,0,2) ;
05360 RooRealVar f2("f2","f2",0.5,0,2) ;
05361
05362
05363 RooRealSumPdf pdf("pdf","pdf",RooArgList(ampl1,ampl2),RooArgList(f1,f2)) ;
05364
05365
05366 RooDataSet* data = pdf.generate(RooArgSet(t,cosa),10000);
05367
05368
05369 pdf.fitTo(*data) ;
05370
05371
05372
05373
05374
05375
05376
05377 TH1* hh_cos = ampl1.createHistogram("hh_cos",t,Binning(50),YVar(cosa,Binning(50))) ;
05378 TH1* hh_sin = ampl2.createHistogram("hh_sin",t,Binning(50),YVar(cosa,Binning(50))) ;
05379 hh_cos->SetLineColor(kBlue) ;
05380 hh_sin->SetLineColor(kBlue) ;
05381
05382
05383
05384
05385 RooPlot* frame1 = t.frame();
05386 data->plotOn(frame1);
05387 pdf.plotOn(frame1);
05388 pdf.plotOn(frame1,Components(ampl1),LineStyle(kDashed));
05389 pdf.plotOn(frame1,Components(ampl2),LineStyle(kDashed),LineColor(kRed));
05390
05391
05392
05393 RooPlot* frame2 = cosa.frame();
05394 data->plotOn(frame2);
05395 pdf.plotOn(frame2);
05396 pdf.plotOn(frame2,Components(ampl1),LineStyle(kDashed));
05397 pdf.plotOn(frame2,Components(ampl2),LineStyle(kDashed),LineColor(kRed));
05398
05399
05400 regPlot(frame1,"rf704_plot1") ;
05401 regPlot(frame2,"rf704_plot2") ;
05402 regTH(hh_cos,"rf704_hh_cos") ;
05403 regTH(hh_sin,"rf704_hh_sin") ;
05404
05405 delete data ;
05406 delete coshGConv ;
05407 delete sinhGConv ;
05408
05409 return kTRUE ;
05410 }
05411 } ;
05412
05413
05414
05415
05416
05417
05418
05419
05420
05421
05422
05423
05424 #ifndef __CINT__
05425 #include "RooGlobalFunc.h"
05426 #endif
05427 #include "RooRealVar.h"
05428 #include "RooDataSet.h"
05429 #include "RooGaussian.h"
05430 #include "RooPolynomial.h"
05431 #include "RooIntegralMorph.h"
05432 #include "RooNLLVar.h"
05433 #include "TCanvas.h"
05434 #include "RooPlot.h"
05435 #include "TH1.h"
05436 using namespace RooFit ;
05437
05438
05439
05440 class TestBasic705 : public RooFitTestUnit
05441 {
05442 public:
05443
05444 Double_t ctol() { return 5e-2 ; }
05445
05446 TestBasic705(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Linear morph operator p.d.f.",refFile,writeRef,verbose) {} ;
05447 Bool_t testCode() {
05448
05449
05450
05451
05452
05453 RooRealVar x("x","x",-20,20) ;
05454
05455
05456 RooRealVar g1mean("g1mean","g1mean",-10) ;
05457 RooGaussian g1("g1","g1",x,g1mean,RooConst(2)) ;
05458
05459
05460 RooPolynomial g2("g2","g2",x,RooArgSet(RooConst(-0.03),RooConst(-0.001))) ;
05461
05462
05463
05464
05465
05466
05467
05468 RooRealVar alpha("alpha","alpha",0,1.0) ;
05469
05470
05471 x.setBins(1000,"cache") ;
05472 alpha.setBins(50,"cache") ;
05473
05474
05475
05476 RooIntegralMorph lmorph("lmorph","lmorph",g1,g2,x,alpha) ;
05477
05478
05479
05480
05481
05482
05483
05484 RooPlot* frame1 = x.frame() ;
05485 g1.plotOn(frame1) ;
05486 g2.plotOn(frame1) ;
05487
05488
05489 alpha.setVal(0.125) ;
05490 lmorph.plotOn(frame1,LineColor(kRed),Name("alt1")) ;
05491 alpha.setVal(0.25) ;
05492 lmorph.plotOn(frame1,LineColor(kRed),Name("alt2")) ;
05493 alpha.setVal(0.375) ;
05494 lmorph.plotOn(frame1,LineColor(kRed),Name("alt3")) ;
05495 alpha.setVal(0.50) ;
05496 lmorph.plotOn(frame1,LineColor(kRed),Name("alt4")) ;
05497 alpha.setVal(0.625) ;
05498 lmorph.plotOn(frame1,LineColor(kRed),Name("alt5")) ;
05499 alpha.setVal(0.75) ;
05500 lmorph.plotOn(frame1,LineColor(kRed),Name("alt6")) ;
05501 alpha.setVal(0.875) ;
05502 lmorph.plotOn(frame1,LineColor(kRed),Name("alt7")) ;
05503 alpha.setVal(0.95) ;
05504 lmorph.plotOn(frame1,LineColor(kRed),Name("alt8")) ;
05505
05506
05507
05508
05509
05510
05511
05512 TH1* hh = lmorph.createHistogram("hh",x,Binning(40),YVar(alpha,Binning(40))) ;
05513 hh->SetLineColor(kBlue) ;
05514
05515
05516
05517
05518
05519
05520 alpha=0.8 ;
05521 RooDataSet* data = lmorph.generate(x,1000) ;
05522
05523
05524 lmorph.setCacheAlpha(kTRUE) ;
05525 lmorph.fitTo(*data) ;
05526
05527
05528 RooPlot* frame2 = x.frame(Bins(100)) ;
05529 data->plotOn(frame2) ;
05530 lmorph.plotOn(frame2) ;
05531
05532
05533
05534
05535
05536
05537 RooPlot* frame3 = alpha.frame(Bins(100),Range(0.5,0.9)) ;
05538
05539
05540 RooNLLVar nll("nll","nll",lmorph,*data) ;
05541 nll.plotOn(frame3,ShiftToZero()) ;
05542
05543 lmorph.setCacheAlpha(kFALSE) ;
05544
05545
05546 regPlot(frame1,"rf705_plot1") ;
05547 regPlot(frame2,"rf705_plot2") ;
05548 regPlot(frame3,"rf705_plot3") ;
05549 regTH(hh,"rf705_hh") ;
05550
05551 delete data ;
05552
05553 return kTRUE;
05554 }
05555 } ;
05556
05557
05558
05559
05560
05561
05562
05563
05564
05565
05566
05567
05568 #ifndef __CINT__
05569 #include "RooGlobalFunc.h"
05570 #endif
05571 #include "RooRealVar.h"
05572 #include "RooDataSet.h"
05573 #include "RooGaussian.h"
05574 #include "RooPolynomial.h"
05575 #include "RooHistPdf.h"
05576 #include "TCanvas.h"
05577 #include "RooPlot.h"
05578 using namespace RooFit ;
05579
05580
05581
05582 class TestBasic706 : public RooFitTestUnit
05583 {
05584 public:
05585 TestBasic706(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Histogram based p.d.f.s",refFile,writeRef,verbose) {} ;
05586 Bool_t testCode() {
05587
05588
05589
05590
05591 RooRealVar x("x","x",0,20) ;
05592 RooPolynomial p("p","p",x,RooArgList(RooConst(0.01),RooConst(-0.01),RooConst(0.0004))) ;
05593
05594
05595
05596
05597
05598
05599
05600 x.setBins(20) ;
05601 RooDataSet* data1 = p.generate(x,500) ;
05602
05603
05604 RooDataHist* hist1 = data1->binnedClone() ;
05605
05606
05607 RooHistPdf histpdf1("histpdf1","histpdf1",x,*hist1,0) ;
05608
05609
05610 RooPlot* frame1 = x.frame(Title("Low statistics histogram pdf"),Bins(100)) ;
05611 data1->plotOn(frame1) ;
05612 histpdf1.plotOn(frame1) ;
05613
05614
05615
05616
05617
05618
05619 x.setBins(10) ;
05620 RooDataSet* data2 = p.generate(x,100000) ;
05621
05622
05623 RooDataHist* hist2 = data2->binnedClone() ;
05624
05625
05626 RooHistPdf histpdf2("histpdf2","histpdf2",x,*hist2,2) ;
05627
05628
05629 RooPlot* frame2 = x.frame(Title("High stats histogram pdf with interpolation"),Bins(100)) ;
05630 data2->plotOn(frame2) ;
05631 histpdf2.plotOn(frame2) ;
05632
05633
05634 regPlot(frame1,"rf607_plot1") ;
05635 regPlot(frame2,"rf607_plot2") ;
05636
05637 delete data1 ;
05638 delete hist1 ;
05639 delete data2 ;
05640 delete hist2 ;
05641
05642 return kTRUE ;
05643 }
05644 } ;
05645
05646
05647
05648
05649
05650
05651
05652
05653
05654
05655
05656
05657 #ifndef __CINT__
05658 #include "RooGlobalFunc.h"
05659 #endif
05660 #include "RooRealVar.h"
05661 #include "RooDataSet.h"
05662 #include "RooGaussian.h"
05663 #include "RooPolynomial.h"
05664 #include "RooKeysPdf.h"
05665 #include "RooNDKeysPdf.h"
05666 #include "RooProdPdf.h"
05667 #include "TCanvas.h"
05668 #include "TH1.h"
05669 #include "RooPlot.h"
05670 using namespace RooFit ;
05671
05672
05673
05674 class TestBasic707 : public RooFitTestUnit
05675 {
05676 public:
05677 TestBasic707(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Kernel estimation p.d.f.s",refFile,writeRef,verbose) {} ;
05678 Bool_t testCode() {
05679
05680
05681
05682
05683
05684 RooRealVar x("x","x",0,20) ;
05685 RooPolynomial p("p","p",x,RooArgList(RooConst(0.01),RooConst(-0.01),RooConst(0.0004))) ;
05686
05687
05688 RooDataSet* data1 = p.generate(x,200) ;
05689
05690
05691
05692
05693
05694
05695
05696
05697
05698 RooKeysPdf kest1("kest1","kest1",x,*data1,RooKeysPdf::MirrorBoth) ;
05699
05700
05701
05702 RooKeysPdf kest2("kest2","kest2",x,*data1,RooKeysPdf::NoMirror) ;
05703
05704
05705
05706
05707 RooKeysPdf kest3("kest3","kest3",x,*data1,RooKeysPdf::MirrorBoth,2) ;
05708
05709
05710
05711 RooPlot* frame = x.frame(Title("Adaptive kernel estimation pdf with and w/o mirroring"),Bins(20)) ;
05712 data1->plotOn(frame) ;
05713 kest1.plotOn(frame) ;
05714 kest2.plotOn(frame,LineStyle(kDashed),LineColor(kRed)) ;
05715
05716
05717
05718 RooPlot* frame2 = x.frame(Title("Adaptive kernel estimation pdf with regular, increased bandwidth")) ;
05719 kest1.plotOn(frame2) ;
05720 kest3.plotOn(frame2,LineColor(kMagenta)) ;
05721
05722
05723
05724
05725
05726
05727
05728 RooRealVar y("y","y",0,20) ;
05729 RooPolynomial py("py","py",y,RooArgList(RooConst(0.01),RooConst(0.01),RooConst(-0.0004))) ;
05730 RooProdPdf pxy("pxy","pxy",RooArgSet(p,py)) ;
05731 RooDataSet* data2 = pxy.generate(RooArgSet(x,y),1000) ;
05732
05733
05734
05735
05736
05737
05738
05739 RooNDKeysPdf kest4("kest4","kest4",RooArgSet(x,y),*data2,"am") ;
05740
05741
05742 RooNDKeysPdf kest5("kest5","kest5",RooArgSet(x,y),*data2,"am",2) ;
05743
05744
05745 TH1* hh_data = data2->createHistogram("hh_data",x,Binning(10),YVar(y,Binning(10))) ;
05746
05747
05748 TH1* hh_pdf = kest4.createHistogram("hh_pdf",x,Binning(25),YVar(y,Binning(25))) ;
05749 TH1* hh_pdf2 = kest5.createHistogram("hh_pdf2",x,Binning(25),YVar(y,Binning(25))) ;
05750 hh_pdf->SetLineColor(kBlue) ;
05751 hh_pdf2->SetLineColor(kMagenta) ;
05752
05753 regPlot(frame,"rf707_plot1") ;
05754 regPlot(frame2,"rf707_plot2") ;
05755 regTH(hh_data,"rf707_hhdata") ;
05756 regTH(hh_pdf,"rf707_hhpdf") ;
05757 regTH(hh_pdf2,"rf707_hhpdf2") ;
05758
05759 delete data1 ;
05760 delete data2 ;
05761
05762 return kTRUE ;
05763 }
05764 } ;
05765
05766
05767
05768
05769
05770
05771
05772
05773
05774
05775
05776
05777 #ifndef __CINT__
05778 #include "RooGlobalFunc.h"
05779 #endif
05780 #include "RooRealVar.h"
05781 #include "RooDataSet.h"
05782 #include "RooGaussian.h"
05783 #include "RooCategory.h"
05784 #include "RooBMixDecay.h"
05785 #include "RooBCPEffDecay.h"
05786 #include "RooBDecay.h"
05787 #include "RooFormulaVar.h"
05788 #include "RooTruthModel.h"
05789 #include "TCanvas.h"
05790 #include "RooPlot.h"
05791 using namespace RooFit ;
05792
05793
05794 class TestBasic708 : public RooFitTestUnit
05795 {
05796 public:
05797 TestBasic708(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("B Physics p.d.f.s",refFile,writeRef,verbose) {} ;
05798 Bool_t testCode() {
05799
05800
05801
05802
05803
05804
05805
05806
05807
05808 RooRealVar dt("dt","dt",-10,10) ;
05809 dt.setBins(40) ;
05810
05811
05812 RooRealVar dm("dm","delta m(B0)",0.472) ;
05813 RooRealVar tau("tau","tau (B0)",1.547) ;
05814 RooRealVar w("w","flavour mistag rate",0.1) ;
05815 RooRealVar dw("dw","delta mistag rate for B0/B0bar",0.1) ;
05816
05817 RooCategory mixState("mixState","B0/B0bar mixing state") ;
05818 mixState.defineType("mixed",-1) ;
05819 mixState.defineType("unmixed",1) ;
05820
05821 RooCategory tagFlav("tagFlav","Flavour of the tagged B0") ;
05822 tagFlav.defineType("B0",1) ;
05823 tagFlav.defineType("B0bar",-1) ;
05824
05825
05826 RooTruthModel tm("tm","truth model",dt) ;
05827
05828
05829 RooBMixDecay bmix("bmix","decay",dt,mixState,tagFlav,tau,dm,w,dw,tm,RooBMixDecay::DoubleSided) ;
05830
05831
05832
05833
05834
05835
05836
05837 RooDataSet* data = bmix.generate(RooArgSet(dt,mixState,tagFlav),10000) ;
05838
05839
05840
05841
05842 RooPlot* frame1 = dt.frame(Title("B decay distribution with mixing (B0/B0bar)")) ;
05843
05844 data->plotOn(frame1,Cut("tagFlav==tagFlav::B0")) ;
05845 bmix.plotOn(frame1,Slice(tagFlav,"B0")) ;
05846
05847 data->plotOn(frame1,Cut("tagFlav==tagFlav::B0bar"),MarkerColor(kCyan)) ;
05848 bmix.plotOn(frame1,Slice(tagFlav,"B0bar"),LineColor(kCyan),Name("alt")) ;
05849
05850
05851
05852 RooPlot* frame2 = dt.frame(Title("B decay distribution of mixed events (B0/B0bar)")) ;
05853
05854 data->plotOn(frame2,Cut("mixState==mixState::mixed&&tagFlav==tagFlav::B0")) ;
05855 bmix.plotOn(frame2,Slice(tagFlav,"B0"),Slice(mixState,"mixed")) ;
05856
05857 data->plotOn(frame2,Cut("mixState==mixState::mixed&&tagFlav==tagFlav::B0bar"),MarkerColor(kCyan)) ;
05858 bmix.plotOn(frame2,Slice(tagFlav,"B0bar"),Slice(mixState,"mixed"),LineColor(kCyan),Name("alt")) ;
05859
05860
05861
05862 RooPlot* frame3 = dt.frame(Title("B decay distribution of unmixed events (B0/B0bar)")) ;
05863
05864 data->plotOn(frame3,Cut("mixState==mixState::unmixed&&tagFlav==tagFlav::B0")) ;
05865 bmix.plotOn(frame3,Slice(tagFlav,"B0"),Slice(mixState,"unmixed")) ;
05866
05867 data->plotOn(frame3,Cut("mixState==mixState::unmixed&&tagFlav==tagFlav::B0bar"),MarkerColor(kCyan)) ;
05868 bmix.plotOn(frame3,Slice(tagFlav,"B0bar"),Slice(mixState,"unmixed"),LineColor(kCyan),Name("alt")) ;
05869
05870
05871
05872
05873
05874
05875
05876
05877
05878
05879
05880
05881
05882 RooRealVar CPeigen("CPeigen","CP eigen value",-1) ;
05883 RooRealVar absLambda("absLambda","|lambda|",1,0,2) ;
05884 RooRealVar argLambda("absLambda","|lambda|",0.7,-1,1) ;
05885 RooRealVar effR("effR","B0/B0bar reco efficiency ratio",1) ;
05886
05887
05888 RooBCPEffDecay bcp("bcp","bcp", dt, tagFlav, tau, dm, w, CPeigen, absLambda, argLambda, effR, dw, tm, RooBCPEffDecay::DoubleSided) ;
05889
05890
05891
05892
05893
05894
05895
05896 RooDataSet* data2 = bcp.generate(RooArgSet(dt,tagFlav),10000) ;
05897
05898
05899 RooPlot* frame4 = dt.frame(Title("B decay distribution with CPV(|l|=1,Im(l)=0.7) (B0/B0bar)")) ;
05900
05901 data2->plotOn(frame4,Cut("tagFlav==tagFlav::B0")) ;
05902 bcp.plotOn(frame4,Slice(tagFlav,"B0")) ;
05903
05904 data2->plotOn(frame4,Cut("tagFlav==tagFlav::B0bar"),MarkerColor(kCyan)) ;
05905 bcp.plotOn(frame4,Slice(tagFlav,"B0bar"),LineColor(kCyan),Name("alt")) ;
05906
05907
05908
05909
05910
05911
05912 absLambda=0.7 ;
05913
05914
05915 RooDataSet* data3 = bcp.generate(RooArgSet(dt,tagFlav),10000) ;
05916
05917
05918 RooPlot* frame5 = dt.frame(Title("B decay distribution with CPV(|l|=0.7,Im(l)=0.7) (B0/B0bar)")) ;
05919
05920 data3->plotOn(frame5,Cut("tagFlav==tagFlav::B0")) ;
05921 bcp.plotOn(frame5,Slice(tagFlav,"B0")) ;
05922
05923 data3->plotOn(frame5,Cut("tagFlav==tagFlav::B0bar"),MarkerColor(kCyan)) ;
05924 bcp.plotOn(frame5,Slice(tagFlav,"B0bar"),LineColor(kCyan),Name("alt")) ;
05925
05926
05927
05928
05929
05930
05931
05932
05933
05934
05935
05936 RooRealVar DGbG("DGbG","DGamma/GammaAvg",0.5,-1,1);
05937 RooRealVar Adir("Adir","-[1-abs(l)**2]/[1+abs(l)**2]",0);
05938 RooRealVar Amix("Amix","2Im(l)/[1+abs(l)**2]",0.7);
05939 RooRealVar Adel("Adel","2Re(l)/[1+abs(l)**2]",0.7);
05940
05941
05942 RooFormulaVar DG("DG","Delta Gamma","@1/@0",RooArgList(tau,DGbG));
05943
05944
05945 RooFormulaVar fsin("fsin","fsin","@0*@1*(1-2*@2)",RooArgList(Amix,tagFlav,w));
05946 RooFormulaVar fcos("fcos","fcos","@0*@1*(1-2*@2)",RooArgList(Adir,tagFlav,w));
05947 RooFormulaVar fsinh("fsinh","fsinh","@0",RooArgList(Adel));
05948
05949
05950 RooBDecay bcpg("bcpg","bcpg",dt,tau,DG,RooConst(1),fsinh,fcos,fsin,dm,tm,RooBDecay::DoubleSided);
05951
05952
05953
05954
05955
05956
05957
05958 RooDataSet* data4 = bcpg.generate(RooArgSet(dt,tagFlav),10000) ;
05959
05960
05961 RooPlot* frame6 = dt.frame(Title("B decay distribution with CPV(Im(l)=0.7,Re(l)=0.7,|l|=1,dG/G=0.5) (B0/B0bar)")) ;
05962
05963 data4->plotOn(frame6,Cut("tagFlav==tagFlav::B0")) ;
05964 bcpg.plotOn(frame6,Slice(tagFlav,"B0")) ;
05965
05966 data4->plotOn(frame6,Cut("tagFlav==tagFlav::B0bar"),MarkerColor(kCyan)) ;
05967 bcpg.plotOn(frame6,Slice(tagFlav,"B0bar"),LineColor(kCyan),Name("alt")) ;
05968
05969
05970 regPlot(frame1,"rf708_plot1") ;
05971 regPlot(frame2,"rf708_plot2") ;
05972 regPlot(frame3,"rf708_plot3") ;
05973 regPlot(frame4,"rf708_plot4") ;
05974 regPlot(frame5,"rf708_plot5") ;
05975 regPlot(frame6,"rf708_plot6") ;
05976
05977 delete data ;
05978 delete data2 ;
05979 delete data3 ;
05980 delete data4 ;
05981
05982 return kTRUE ;
05983 }
05984 } ;
05985
05986
05987
05988
05989
05990
05991
05992
05993
05994
05995 #ifndef __CINT__
05996 #include "RooGlobalFunc.h"
05997 #endif
05998 #include "RooRealVar.h"
05999 #include "RooDataSet.h"
06000 #include "RooGaussian.h"
06001 #include "RooChebychev.h"
06002 #include "RooAddPdf.h"
06003 #include "RooMCStudy.h"
06004 #include "RooPlot.h"
06005 #include "TCanvas.h"
06006 #include "TH2.h"
06007 #include "RooFitResult.h"
06008 #include "TStyle.h"
06009 #include "TDirectory.h"
06010
06011 using namespace RooFit ;
06012
06013
06014
06015 class TestBasic801 : public RooFitTestUnit
06016 {
06017 public:
06018 TestBasic801(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Automated MC studies",refFile,writeRef,verbose) {} ;
06019 Bool_t testCode() {
06020
06021
06022
06023
06024
06025 RooRealVar x("x","x",0,10) ;
06026 x.setBins(40) ;
06027
06028
06029 RooRealVar mean("mean","mean of gaussians",5,0,10) ;
06030 RooRealVar sigma1("sigma1","width of gaussians",0.5) ;
06031 RooRealVar sigma2("sigma2","width of gaussians",1) ;
06032
06033 RooGaussian sig1("sig1","Signal component 1",x,mean,sigma1) ;
06034 RooGaussian sig2("sig2","Signal component 2",x,mean,sigma2) ;
06035
06036
06037 RooRealVar a0("a0","a0",0.5,0.,1.) ;
06038 RooRealVar a1("a1","a1",-0.2,-1,1.) ;
06039 RooChebychev bkg("bkg","Background",x,RooArgSet(a0,a1)) ;
06040
06041
06042 RooRealVar sig1frac("sig1frac","fraction of component 1 in signal",0.8,0.,1.) ;
06043 RooAddPdf sig("sig","Signal",RooArgList(sig1,sig2),sig1frac) ;
06044
06045
06046 RooRealVar nbkg("nbkg","number of background events,",150,0,1000) ;
06047 RooRealVar nsig("nsig","number of signal events",150,0,1000) ;
06048 RooAddPdf model("model","g1+g2+a",RooArgList(bkg,sig),RooArgList(nbkg,nsig)) ;
06049
06050
06051
06052
06053
06054
06055
06056
06057
06058
06059
06060
06061
06062
06063
06064
06065
06066
06067
06068
06069
06070 RooMCStudy* mcstudy = new RooMCStudy(model,x,Binned(kTRUE),Silence(),Extended(),
06071 FitOptions(Save(kTRUE),PrintEvalErrors(0))) ;
06072
06073
06074
06075
06076
06077
06078 mcstudy->generateAndFit(100) ;
06079
06080
06081
06082
06083
06084
06085
06086 RooPlot* frame1 = mcstudy->plotParam(mean,Bins(40)) ;
06087 RooPlot* frame2 = mcstudy->plotError(mean,Bins(40)) ;
06088 RooPlot* frame3 = mcstudy->plotPull(mean,Bins(40),FitGauss(kTRUE)) ;
06089
06090
06091 RooPlot* frame4 = mcstudy->plotNLL(Bins(40)) ;
06092
06093 regPlot(frame1,"rf801_plot1") ;
06094 regPlot(frame2,"rf801_plot2") ;
06095 regPlot(frame3,"rf801_plot3") ;
06096 regPlot(frame4,"rf801_plot4") ;
06097
06098 delete mcstudy ;
06099
06100 return kTRUE ;
06101 }
06102 } ;
06103
06104
06105
06106
06107
06108
06109
06110
06111
06112
06113
06114 #ifndef __CINT__
06115 #include "RooGlobalFunc.h"
06116 #endif
06117 #include "RooRealVar.h"
06118 #include "RooDataSet.h"
06119 #include "RooGaussian.h"
06120 #include "RooChebychev.h"
06121 #include "RooAddPdf.h"
06122 #include "RooMCStudy.h"
06123 #include "RooChi2MCSModule.h"
06124 #include "RooPlot.h"
06125 #include "TCanvas.h"
06126 #include "TH1.h"
06127 #include "TDirectory.h"
06128
06129 using namespace RooFit ;
06130
06131
06132
06133 class TestBasic802 : public RooFitTestUnit
06134 {
06135 public:
06136 TestBasic802(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("MC Study with chi^2 calculator",refFile,writeRef,verbose) {} ;
06137 Bool_t testCode() {
06138
06139
06140
06141
06142
06143 RooRealVar x("x","x",-10,10) ;
06144 x.setBins(10) ;
06145 RooRealVar mean("mean","mean of gaussian",0) ;
06146 RooRealVar sigma("sigma","width of gaussian",5,1,10) ;
06147
06148
06149 RooGaussian gauss("gauss","gaussian PDF",x,mean,sigma) ;
06150
06151
06152
06153
06154
06155
06156
06157 RooMCStudy* mcs = new RooMCStudy(gauss,x,Silence(),Binned()) ;
06158
06159
06160 RooChi2MCSModule chi2mod ;
06161 mcs->addModule(chi2mod) ;
06162
06163
06164 mcs->generateAndFit(200,1000) ;
06165
06166
06167
06168
06169 RooRealVar* chi2 = (RooRealVar*) mcs->fitParDataSet().get()->find("chi2") ;
06170 RooRealVar* prob = (RooRealVar*) mcs->fitParDataSet().get()->find("prob") ;
06171
06172 TH1* h_chi2 = new TH1F("h_chi2","",40,0,20) ;
06173 TH1* h_prob = new TH1F("h_prob","",40,0,1) ;
06174
06175 mcs->fitParDataSet().fillHistogram(h_chi2,*chi2) ;
06176 mcs->fitParDataSet().fillHistogram(h_prob,*prob) ;
06177
06178
06179
06180
06181
06182
06183
06184 RooRealVar mean2("mean2","mean of gaussian 2",0.5) ;
06185 RooGaussian gauss2("gauss2","gaussian PDF2",x,mean2,sigma) ;
06186
06187
06188
06189
06190 RooMCStudy* mcs2 = new RooMCStudy(gauss2,x,FitModel(gauss),Silence(),Binned()) ;
06191
06192
06193 RooChi2MCSModule chi2mod2 ;
06194 mcs2->addModule(chi2mod2) ;
06195
06196
06197 mcs2->generateAndFit(200,1000) ;
06198
06199
06200
06201
06202 TH1* h2_chi2 = new TH1F("h2_chi2","",40,0,20) ;
06203 TH1* h2_prob = new TH1F("h2_prob","",40,0,1) ;
06204
06205 mcs2->fitParDataSet().fillHistogram(h2_chi2,*chi2) ;
06206 mcs2->fitParDataSet().fillHistogram(h2_prob,*prob) ;
06207
06208 h_chi2->SetLineColor(kRed) ;
06209 h_prob->SetLineColor(kRed) ;
06210
06211 regTH(h_chi2,"rf802_hist_chi2") ;
06212 regTH(h2_chi2,"rf802_hist2_chi2") ;
06213 regTH(h_prob,"rf802_hist_prob") ;
06214 regTH(h2_prob,"rf802_hist2_prob") ;
06215
06216 delete mcs ;
06217 delete mcs2 ;
06218
06219 return kTRUE ;
06220 }
06221 } ;
06222
06223
06224
06225
06226
06227
06228
06229
06230
06231
06232
06233 #ifndef __CINT__
06234 #include "RooGlobalFunc.h"
06235 #endif
06236 #include "RooRealVar.h"
06237 #include "RooDataSet.h"
06238 #include "RooGaussian.h"
06239 #include "RooChebychev.h"
06240 #include "RooAddPdf.h"
06241 #include "RooMCStudy.h"
06242 #include "RooRandomizeParamMCSModule.h"
06243 #include "RooDLLSignificanceMCSModule.h"
06244 #include "RooPlot.h"
06245 #include "TCanvas.h"
06246 #include "TH1.h"
06247 #include "TDirectory.h"
06248
06249 using namespace RooFit ;
06250
06251
06252 class TestBasic803 : public RooFitTestUnit
06253 {
06254 public:
06255 TestBasic803(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("MC Study with param rand. and Z calc",refFile,writeRef,verbose) {} ;
06256 Bool_t testCode() {
06257
06258
06259
06260
06261
06262
06263
06264
06265 RooRealVar mjjj("mjjj","m(3jet) (GeV)",100,85.,350.) ;
06266
06267
06268 RooRealVar mtop("mtop","m(top)",162) ;
06269 RooRealVar wtop("wtop","m(top) resolution",15.2) ;
06270 RooGaussian sig("sig","top signal",mjjj,mtop,wtop) ;
06271
06272
06273 RooRealVar c0("c0","Chebychev coefficient 0",-0.846,-1.,1.) ;
06274 RooRealVar c1("c1","Chebychev coefficient 1", 0.112, 0.,1.) ;
06275 RooRealVar c2("c2","Chebychev coefficient 2", 0.076, 0.,1.) ;
06276 RooChebychev bkg("bkg","combinatorial background",mjjj,RooArgList(c0,c1,c2)) ;
06277
06278
06279 RooRealVar nsig("nsig","number of signal events",53,0,1e3) ;
06280 RooRealVar nbkg("nbkg","number of background events",103,0,5e3) ;
06281 RooAddPdf model("model","model",RooArgList(sig,bkg),RooArgList(nsig,nbkg)) ;
06282
06283
06284
06285
06286
06287
06288
06289
06290 RooMCStudy* mcs = new RooMCStudy(model,mjjj,Binned(),Silence(),Extended(kTRUE),
06291 FitOptions(Extended(kTRUE),PrintEvalErrors(-1))) ;
06292
06293
06294
06295
06296
06297
06298
06299
06300
06301
06302
06303
06304
06305
06306 RooRandomizeParamMCSModule randModule ;
06307 randModule.sampleSumUniform(RooArgSet(nsig,nbkg),50,500) ;
06308 mcs->addModule(randModule) ;
06309
06310
06311
06312
06313
06314
06315
06316
06317 RooDLLSignificanceMCSModule sigModule(nsig,0) ;
06318 mcs->addModule(sigModule) ;
06319
06320
06321
06322
06323
06324
06325 mcs->generateAndFit(50) ;
06326
06327
06328 RooRealVar* ngen = (RooRealVar*) mcs->fitParDataSet().get()->find("ngen") ;
06329 RooRealVar* dll = (RooRealVar*) mcs->fitParDataSet().get()->find("dll_nullhypo_nsig") ;
06330 RooRealVar* z = (RooRealVar*) mcs->fitParDataSet().get()->find("significance_nullhypo_nsig") ;
06331 RooRealVar* nsigerr = (RooRealVar*) mcs->fitParDataSet().get()->find("nsigerr") ;
06332
06333 TH1* dll_vs_ngen = new TH2F("h_dll_vs_ngen" ,"",40,0,500,40,0,50) ;
06334 TH1* z_vs_ngen = new TH2F("h_z_vs_ngen" ,"",40,0,500,40,0,10) ;
06335 TH1* errnsig_vs_ngen = new TH2F("h_nsigerr_vs_ngen","",40,0,500,40,0,30) ;
06336 TH1* errnsig_vs_nsig = new TH2F("h_nsigerr_vs_nsig","",40,0,200,40,0,30) ;
06337
06338 mcs->fitParDataSet().fillHistogram(dll_vs_ngen,RooArgList(*ngen,*dll)) ;
06339 mcs->fitParDataSet().fillHistogram(z_vs_ngen,RooArgList(*ngen,*z)) ;
06340 mcs->fitParDataSet().fillHistogram(errnsig_vs_ngen,RooArgList(*ngen,*nsigerr)) ;
06341 mcs->fitParDataSet().fillHistogram(errnsig_vs_nsig,RooArgList(nsig,*nsigerr)) ;
06342
06343 regTH(dll_vs_ngen,"rf803_dll_vs_ngen") ;
06344 regTH(z_vs_ngen,"rf803_z_vs_ngen") ;
06345 regTH(errnsig_vs_ngen,"rf803_errnsig_vs_ngen") ;
06346 regTH(errnsig_vs_nsig,"rf803_errnsig_vs_nsig") ;
06347
06348 delete mcs ;
06349
06350 return kTRUE ;
06351
06352 }
06353 } ;
06354
06355
06356
06357
06358
06359
06360
06361
06362
06363
06364
06365
06366
06367
06368
06369 #ifndef __CINT__
06370 #include "RooGlobalFunc.h"
06371 #endif
06372 #include "RooRealVar.h"
06373 #include "RooDataSet.h"
06374 #include "RooGaussian.h"
06375 #include "RooPolynomial.h"
06376 #include "RooAddPdf.h"
06377 #include "RooProdPdf.h"
06378 #include "RooMCStudy.h"
06379 #include "RooPlot.h"
06380 #include "TCanvas.h"
06381 #include "TH1.h"
06382 using namespace RooFit ;
06383
06384
06385 class TestBasic804 : public RooFitTestUnit
06386 {
06387 public:
06388 TestBasic804(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("MC Studies with aux. obs. constraints",refFile,writeRef,verbose) {} ;
06389
06390 Double_t htol() { return 0.1 ; }
06391
06392 Bool_t testCode() {
06393
06394
06395
06396
06397
06398 RooRealVar x("x","x",-10,10) ;
06399
06400
06401 RooRealVar m("m","m",0,-10,10) ;
06402 RooRealVar s("s","s",2,0.1,10) ;
06403 RooGaussian g("g","g",x,m,s) ;
06404
06405
06406 RooPolynomial p("p","p",x) ;
06407
06408
06409 RooRealVar f("f","f",0.4,0.,1.) ;
06410 RooAddPdf sum("sum","sum",RooArgSet(g,p),f) ;
06411
06412
06413 RooGaussian fconstraint("fconstraint","fconstraint",f,RooConst(0.7),RooConst(0.1)) ;
06414
06415
06416 RooProdPdf sumc("sumc","sum with constraint",RooArgSet(sum,fconstraint)) ;
06417
06418
06419
06420
06421
06422
06423
06424 RooMCStudy mcs(sumc,x,Constrain(f),Silence(),Binned(),FitOptions(PrintLevel(-1))) ;
06425
06426
06427
06428
06429 mcs.generateAndFit(50,2000) ;
06430
06431
06432 RooRealVar* f_gen = (RooRealVar*) mcs.fitParDataSet().get()->find("f_gen") ;
06433 TH1* h_f_gen = new TH1F("h_f_gen","",40,0,1) ;
06434 mcs.fitParDataSet().fillHistogram(h_f_gen,*f_gen) ;
06435
06436
06437 RooPlot* frame1 = mcs.plotParam(f,Bins(40),Range(0.4,1)) ;
06438 frame1->SetTitle("Distribution of fitted f values") ;
06439
06440
06441 RooPlot* frame2 = mcs.plotPull(f,Bins(40),Range(-3,3)) ;
06442 frame1->SetTitle("Distribution of f pull values") ;
06443
06444 regTH(h_f_gen,"rf804_h_f_gen") ;
06445 regPlot(frame1,"rf804_plot1") ;
06446 regPlot(frame2,"rf804_plot2") ;
06447
06448 return kTRUE ;
06449 }
06450 } ;
06451