本文整理汇总了C++中RooFitResult::randomizePars方法的典型用法代码示例。如果您正苦于以下问题:C++ RooFitResult::randomizePars方法的具体用法?C++ RooFitResult::randomizePars怎么用?C++ RooFitResult::randomizePars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RooFitResult
的用法示例。
在下文中一共展示了RooFitResult::randomizePars方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
for(Int_t j=0;j<myRes;j++){
if(i==0) l = 7;
else if(i==1) l = 6;
else if(i==2) l = 11;
else if(i==3) l = 4;
else if(i==4) l = 5;
else if(i==5) l = 3;
else if(i==6) l = 9;
else if(i==7) l = 10;
else if(i==8) l = 12;
else if(i==9) l = 8;
else if(i==10) l = 2;
else if(i==11) l = 0;
if(j==0) m = 7;
else if(j==1) m = 6;
else if(j==2) m = 11;
else if(j==3) m = 4;
else if(j==4) m = 5;
else if(j==5) m = 3;
else if(j==6) m = 9;
else if(j==7) m = 10;
else if(j==8) m = 12;
else if(j==9) m = 8;
else if(j==10) m = 2;
else if(j==11) m = 0;
mynorm[i][j] = normarray[l][m];
}
}
//do 100 experiments and extract parameters using covariance matrix
for(Int_t l=0;l<300;l++){
RooArgList listpar = fitRes->randomizePars();
if(l==0) listpar.Print();
Double_t mynormD0 = 0.;
EvtComplex coeff_i(0.,0.), coeff_j(0.,0.);
for(Int_t i=0;i<2*myRes;i++){
for(Int_t j=0;j<2*myRes;j++){
if(i==(2*myRes - 2)) coeff_i = EvtComplex(1.,0.);
else coeff_i = EvtComplex(((RooAbsReal*)listpar.at(i))->getVal()*cos(((RooAbsReal*)listpar.at(i+1))->getVal()),
((RooAbsReal*)listpar.at(i))->getVal()*sin(((RooAbsReal*)listpar.at(i+1))->getVal()));
if(j==(2*myRes - 2)) coeff_j = EvtComplex(1.,0.);
else coeff_j = EvtComplex(((RooAbsReal*)listpar.at(j))->getVal()*cos(((RooAbsReal*)listpar.at(j+1))->getVal()),
((RooAbsReal*)listpar.at(j))->getVal()*sin(((RooAbsReal*)listpar.at(j+1))->getVal()));
mynormD0 += real(coeff_i*conj(coeff_j)*(mynorm[i/2][j/2]));
j++;
}
i++;
}
//now calculate the fit fractions
for(Int_t i=0;i<2*myRes;i++){
Double_t fitfrac = 0.;
if(i==(2*myRes - 2)) fitfrac = abs(mynorm[i/2][i/2])/mynormD0;
else fitfrac = abs2( ((RooAbsReal*)listpar.at(i))->getVal())*abs(mynorm[i/2][i/2])/mynormD0;
fitty[i/2].Fill(fitfrac);
i++;
}
}// nexperiments
Double_t tot_frac = 0.;
for(Int_t i=0;i<myRes;i++){
示例2: main
//.........这里部分代码省略.........
d0LifetimeErr.setBins(10);
RooDataSet *ProtoData_bkg = (RooDataSet*)databkg->reduce(RooArgSet(d0LifetimeErr));
TH1F *err_bkg_h = (TH1F*)d0LifetimeErr.createHistogram("err_bkg_h");
ProtoData_bkg->fillHistogram(err_bkg_h,RooArgSet(d0LifetimeErr));
err_bkg_h->Scale(err_sig_h->Integral()/err_bkg_h->Integral());
RooDataHist terr_bkg("terr_bkg","terr_bkg",RooArgSet(d0LifetimeErr),err_bkg_h);
RooHistPdf terr_bkg_pdf("terr_bkg_pdf","terr_bkg_pdf",RooArgSet(d0LifetimeErr),terr_bkg,3);
RooDataSet *ProtoData_flav_1 = (RooDataSet*)RSdata->reduce(RooArgSet(D0flav));
RooDataSet *ProtoData_flav = (RooDataSet*)ProtoData_flav_1->reduce(EventRange(1,(Int_t)((1508 + 791)*ratio)));
//RooDataHist flav_sig("flav_sig","flav_sig",RooArgSet(D0flav),*ProtoData_flav);
//RooHistPdf flav_sig_pdf("flav_sig_pdf","flav_sig_pdf",RooArgSet(D0flav),flav_sig);
RooDataSet *ProtoData_flav_bkg_1 = (RooDataSet*)databkg->reduce(RooArgSet(D0flav));
RooDataSet *ProtoData_flav_bkg = (RooDataSet*)ProtoData_flav_bkg_1->reduce(EventRange(1,(Int_t)((663 + 47)*ratio)));
//RooDataHist flav_bkg("flav_bkg","flav_bkg",RooArgSet(D0flav),*ProtoData_flav_bkg);
//RooHistPdf flav_bkg_pdf("flav_bkg_pdf","flav_bkg_pdf",RooArgSet(D0flav),flav_bkg);
ProtoData_flav->append(*ProtoData_flav_bkg);
RooProdPdf totsig_norm("totsig_norm","totsig_norm",RooArgSet(terr_sig_pdf),Conditional(TOTTime,observ));
RooProdPdf totmis_norm("totmis_norm","totmis_norm",RooArgSet(terr_sig_pdf),Conditional(Tot_mis,observ));
RooProdPdf totbkg_norm("totbkg_norm","totbkg_norm",RooArgSet(terr_bkg_pdf),Conditional(Tot_comb,observ));
/*
RooProdPdf totsig_norm("totsig_norm","totsig_norm",RooArgSet(terr_sig_pdf),Conditional(TOTsigD0,observ));
RooProdPdf totmis_norm("totmis_norm","totmis_norm",RooArgSet(terr_sig_pdf),Conditional(Tot_mis,observ));
RooProdPdf totbkg_norm("totbkg_norm","totbkg_norm",RooArgSet(terr_bkg_pdf),Conditional(Tot_comb,observ));
*/
//Signal + background
RooAddPdf TOTpdf("TOTpdf","TOTpdf",RooArgList(totsig_norm,totmis_norm,totbkg_norm),RooArgList(Nsig,Nmis,Ncomb));
RooMCStudy mgr(totsig_norm,tot_var,FitOptions(Save(1),Extended(0),Minos(0)),Extended(0),ConditionalObservables(D0flav),RooFit::ProtoData(*ProtoData_flav,1));
//RooMCStudy mgr(totsig_norm,tot_var,FitOptions(ConditionalObservables(RooArgSet(D0flav)),Save(1),Extended(0)),Extended(0),RooFit::ProtoData(*ConditDataset,1));
TString dataname(filename);
dataname.Append(".dat");
TString toyname(filename);
toyname.Append("_fixed.root");
if(doGen && !doFit) mgr.generate(nexp,nev,kFALSE,dataname);
if(doFit && !doGen) mgr.fit(nexp,dataname);
if(doGen && doFit) mgr.generateAndFit(nexp,nev,kFALSE,dataname);
if(doFit){
TFile f(toyname,"RECREATE");
f.cd();
(RooFitResult*)mgr.fitResult(0)->Write();
mgr.fitParDataSet().tree().Write();
f.Close();
}
if(extract){
RooFitResult *theRes = (RooFitResult*)mgr.fitResult(0);
RooRealVar myc1("myc1","myc1",-10.,10.);
RooRealVar myc2("myc2","myc2",-10.,10.);
RooRealVar myratio("myratio","myratio",0.,0.,1.);
RooRealVar myx("myx","myx",0.,-1.,1.);
RooRealVar myy("myy","myy",0.,-1.,1.);
Double_t NrsNws = 2760./1198329;
Double_t ratioerr = sqrt(pow(96.,2.) + pow(NrsNws,2.)*pow(2760.,2.))/1198329.;
RooDataSet *parFloat = new RooDataSet("parFloat","parFloat",RooArgList(myratio,myx,myy));
RooTimepdf mysigD0("mysigD0","mysigD0",d0Lifetime,m2Kpi_d0mass,m2Kpi0_d0mass,gm,&dalitzSpace,tau,c1,c2,-1,dirname);
Double_t myDenom = mysigD0.createIntegral(RooArgSet(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime))->getVal();
cout << "x' " << c2.getVal()*sqrt(NrsNws/myDenom) << endl;
cout << "y' " << c1.getVal()*sqrt(NrsNws/myDenom) << endl;
cout << "r0^2 " << NrsNws/myDenom << endl;
for(Int_t j=0;j<1000;j++){
cout << "Performing step number " << j << endl;
RooArgList floated = theRes->randomizePars();
myc1.setVal(((RooAbsReal*)floated.find("c1"))->getVal());
myc2.setVal(((RooAbsReal*)floated.find("c2"))->getVal());
Double_t myDenom = mysigD0.createIntegral(RooArgSet(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime))->getVal();
Double_t myNum = RooRandom::randomGenerator()->Gaus(NrsNws,ratioerr);
myratio.setVal(myNum/myDenom);
myx.setVal(myc2.getVal()*sqrt((myNum/myDenom)));
myy.setVal(myc1.getVal()*sqrt((myNum/myDenom)));
parFloat->add(RooArgSet(myratio,myx,myy));
}
TString floatname(filename);
floatname.Append("_float.root");
TFile *f1 = new TFile(floatname,"RECREATE");
f1->cd();
parFloat->Write();
f1->Close();
}
return 0;
}
示例3: main
//.........这里部分代码省略.........
RooProdPdf totbkg_norm23("totbkg_norm23","totbkg_norm23",RooArgSet(terr_bkg_pdf),Conditional(Tot_comb23,observ23));
//Signal + background
RooAddPdf TOTpdf("TOTpdf","TOTpdf",RooArgList(totsig_norm,totmis_norm,totbkg_norm),RooArgList(Nsig,Nmis,Ncomb));
RooAddPdf TOTpdf23("TOTpdf23","TOTpdf23",RooArgList(totsig_norm23,totmis_norm23,totbkg_norm23),RooArgList(Nsig,Nmis,Ncomb));
if(doFit){
RooFitResult *theRes = TOTpdf.fitTo(*dataWS,Save(1),Minos(0),Extended(0));
string filename = "syst_root/fit_WS_" + name + ".root";
TFile fout(filename.c_str(),"RECREATE");
fout.cd();
theRes->Write();
fout.Close();
}
if(extract){
TFile f("fitWS.root");
RooFitResult* theRes = (RooFitResult*)f.Get("nll");
RooRealVar myc1("myc1","myc1",-10.,10.);
RooRealVar myc2("myc2","myc2",-10.,10.);
RooRealVar myratio("myratio","myratio",0.,0.,1.);
RooRealVar myx("myx","myx",0.,-1.,1.);
RooRealVar myy("myy","myy",0.,-1.,1.);
Double_t NrsNws = 2562./1132332.;
Double_t ratioerr = sqrt(pow(89.,2.) + pow(NrsNws,2.)*pow(2862.,2.))/1132332.;
RooDataSet *parFloat = new RooDataSet("parFloat","parFloat",RooArgList(myratio,myx,myy));
for(Int_t j=0;j<400;j++){
cout << "Performing step number " << j << endl;
RooArgList floated = theRes->randomizePars();
myc1.setVal(((RooAbsReal*)floated.find("c1"))->getVal());
myc2.setVal(((RooAbsReal*)floated.find("c2"))->getVal());
RooTimepdf mysigD0("mysigD0","mysigD0",d0Lifetime,m2Kpi_d0mass,m2Kpi0_d0mass,gm,&dalitzSpace,tau,myc1,myc2,-1,dirname);
Double_t myDenom = mysigD0.createIntegral(RooArgSet(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime))->getVal();
Double_t myNum = RooRandom::randomGenerator()->Gaus(NrsNws,ratioerr);
myratio.setVal(myNum/myDenom);
myx.setVal(myc2.getVal()*sqrt((myNum/myDenom)));
myy.setVal(myc1.getVal()*sqrt((myNum/myDenom)));
parFloat->add(RooArgSet(myratio,myx,myy));
}
TFile *f1 = new TFile("fitWS_float.root","RECREATE");
f1->cd();
parFloat->Write();
f1->Close();
}
if(doChi2){
m2Kpi_d0mass.setBins(40);
m2Kpi0_d0mass.setBins(40);
RooDataSet *dterr_ds = (RooDataSet*)dataWS->reduce(RooArgSet(d0LifetimeErr));
TH2F *dphist_data = (TH2F*)m2Kpi_d0mass.createHistogram("dphist_data",m2Kpi0_d0mass);
dataWS->fillHistogram(dphist_data,RooArgSet(m2Kpi_d0mass,m2Kpi0_d0mass));
RooDataSet *pdf_ds = (RooDataSet*)TOTpdf.generate(RooArgSet(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime),dataWS->numEntries(),RooFit::ProtoData(*dterr_ds,1));
TH2F *dphist = (TH2F*)m2Kpi_d0mass.createHistogram("dphist",m2Kpi0_d0mass);