本文整理汇总了C++中RooFitResult::SetName方法的典型用法代码示例。如果您正苦于以下问题:C++ RooFitResult::SetName方法的具体用法?C++ RooFitResult::SetName怎么用?C++ RooFitResult::SetName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RooFitResult
的用法示例。
在下文中一共展示了RooFitResult::SetName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makeInvertedANFit
RooWorkspace* makeInvertedANFit(TTree* tree, float forceSigma=-1, bool constrainMu=false, float forceMu=-1) {
RooWorkspace *ws = new RooWorkspace("ws","");
std::vector< TString (*)(TString, RooRealVar&, RooWorkspace&) > bkgPdfList;
bkgPdfList.push_back(makeSingleExp);
bkgPdfList.push_back(makeDoubleExp);
#if DEBUG==0
//bkgPdfList.push_back(makeTripleExp);
bkgPdfList.push_back(makeModExp);
bkgPdfList.push_back(makeSinglePow);
bkgPdfList.push_back(makeDoublePow);
bkgPdfList.push_back(makePoly2);
bkgPdfList.push_back(makePoly3);
#endif
RooRealVar mgg("mgg","m_{#gamma#gamma}",103,160,"GeV");
mgg.setBins(38);
mgg.setRange("sideband_low", 103,120);
mgg.setRange("sideband_high",131,160);
mgg.setRange("signal",120,131);
RooRealVar MR("MR","",0,3000,"GeV");
MR.setBins(60);
RooRealVar Rsq("t1Rsq","",0,1,"GeV");
Rsq.setBins(20);
RooRealVar hem1_M("hem1_M","",-1,2000,"GeV");
hem1_M.setBins(40);
RooRealVar hem2_M("hem2_M","",-1,2000,"GeV");
hem2_M.setBins(40);
RooRealVar ptgg("ptgg","p_{T}^{#gamma#gamma}",0,500,"GeV");
ptgg.setBins(50);
RooDataSet data("data","",tree,RooArgSet(mgg,MR,Rsq,hem1_M,hem2_M,ptgg));
RooDataSet* blind_data = (RooDataSet*)data.reduce("mgg<121 || mgg>130");
std::vector<TString> tags;
//fit many different background models
for(auto func = bkgPdfList.begin(); func != bkgPdfList.end(); func++) {
TString tag = (*func)("bonly",mgg,*ws);
tags.push_back(tag);
ws->pdf("bonly_"+tag+"_ext")->fitTo(data,RooFit::Strategy(0),RooFit::Extended(kTRUE),RooFit::Range("sideband_low,sideband_high"));
RooFitResult* bres = ws->pdf("bonly_"+tag+"_ext")->fitTo(data,RooFit::Strategy(2),RooFit::Save(kTRUE),RooFit::Extended(kTRUE),RooFit::Range("sideband_low,sideband_high"));
bres->SetName(tag+"_bonly_fitres");
ws->import(*bres);
//make blinded fit
RooPlot *fmgg_b = mgg.frame();
blind_data->plotOn(fmgg_b,RooFit::Range("sideband_low,sideband_high"));
TBox blindBox(121,fmgg_b->GetMinimum()-(fmgg_b->GetMaximum()-fmgg_b->GetMinimum())*0.015,130,fmgg_b->GetMaximum());
blindBox.SetFillColor(kGray);
fmgg_b->addObject(&blindBox);
ws->pdf("bonly_"+tag+"_ext")->plotOn(fmgg_b,RooFit::LineColor(kRed),RooFit::Range("Full"),RooFit::NormRange("sideband_low,sideband_high"));
fmgg_b->SetName(tag+"_blinded_frame");
ws->import(*fmgg_b);
delete fmgg_b;
//set all the parameters constant
RooArgSet* vars = ws->pdf("bonly_"+tag)->getVariables();
RooFIter iter = vars->fwdIterator();
RooAbsArg* a;
while( (a = iter.next()) ){
if(string(a->GetName()).compare("mgg")==0) continue;
static_cast<RooRealVar*>(a)->setConstant(kTRUE);
}
//make the background portion of the s+b fit
(*func)("b",mgg,*ws);
RooRealVar sigma(tag+"_s_sigma","",5,0,100);
if(forceSigma!=-1) {
sigma.setVal(forceSigma);
sigma.setConstant(true);
}
RooRealVar mu(tag+"_s_mu","",126,120,132);
if(forceMu!=-1) {
mu.setVal(forceMu);
mu.setConstant(true);
}
RooGaussian sig(tag+"_sig_model","",mgg,mu,sigma);
RooRealVar Nsig(tag+"_sb_Ns","",5,0,100);
RooRealVar Nbkg(tag+"_sb_Nb","",100,0,100000);
RooRealVar HiggsMass("HiggsMass","",125.1);
RooRealVar HiggsMassError("HiggsMassError","",0.24);
RooGaussian HiggsMassConstraint("HiggsMassConstraint","",mu,HiggsMass,HiggsMassError);
RooAddPdf fitModel(tag+"_sb_model","",RooArgList( *ws->pdf("b_"+tag), sig ),RooArgList(Nbkg,Nsig));
RooFitResult* sbres;
//.........这里部分代码省略.........
示例2: makejpsifit
//.........这里部分代码省略.........
RooRealVar cbBias ("#Deltam_{CB}", "CB Bias", -.01, -10, 10, "GeV/c^{2}");
RooRealVar cbSigma("#sigma_{CB}", "CB Width", 1.5, 0.01, 5.0, "GeV/c^{2}");
RooRealVar cbCut ("a_{CB}","CB Cut", 1.0, 1.0, 3.0);
RooRealVar cbPower("n_{CB}","CB Order", 2.5, 0.1, 20.0);
cbCut.setVal(cutoff_cb);
cbPower.setVal(power_cb);
// Just checking
//cbCut.Print();
//cbPower.Print();
//Breit_Wigner parameters
RooRealVar bwMean("m_{JPsi}","BW Mean", 3.096916, "GeV/c^{2}");
bwMean.setVal(mean_bw);
RooRealVar bwWidth("#Gamma_{JPsi}", "BW Width", 92.9e-6, "GeV/c^{2}");
bwWidth.setVal(gamma_bw);
// Fix the Breit-Wigner parameters to PDG values
bwMean.setConstant(kTRUE);
bwWidth.setConstant(kTRUE);
// Exponential Background parameters
RooRealVar expRate("#lambda_{exp}", "Exponential Rate", -0.064, -1, 1);
RooRealVar c0("c_{0}", "c0", 1., 0., 50.);
//Number of Signal and Background events
RooRealVar nsig("N_{S}", "# signal events", 524, 0.1, 10000000000.);
RooRealVar nbkg("N_{B}", "# background events", 43, 1., 10000000.);
//============================ P.D.F.s=============================
// Mass signal for two decay electrons p.d.f.
RooBreitWigner bw("bw", "bw", mass, bwMean, bwWidth);
RooCBShape cball("cball", "Crystal Ball", mass, cbBias, cbSigma, cbCut, cbPower);
RooFFTConvPdf BWxCB("BWxCB", "bw X crystal ball", mass, bw, cball);
// Mass background p.d.f.
RooExponential bg("bg", "exp. background", mass, expRate);
// Mass model for signal electrons p.d.f.
RooAddPdf model("model", "signal", RooArgList(BWxCB), RooArgList(nsig));
TStopwatch t ;
t.Start() ;
double fitmin, fitmax;
if(isMC) {
fitmin = (etaBin==0) ? 3.00 : 2.7;
fitmax = (etaBin==0) ? 3.20 : 3.4;
} else {
fitmin = (etaBin==0) ? ( (ptBin>=2) ? 3.01 : 3.02 ) : 2.7;
fitmax = (etaBin==0) ? ( (ptBin==3) ? 3.23 : 3.22 ) : 3.4;
}
RooFitResult *fitres = model.fitTo(*bdata,Range(fitmin,fitmax),Hesse(1),Minos(1),Timer(1),Save(1));
fitres->SetName("fitres");
t.Print() ;
TCanvas* c = new TCanvas("c","Unbinned Invariant Mass Fit", 0,0,800,600);
//========================== Plotting ============================
//Create a frame
RooPlot* plot = mass.frame(Range(minMass,maxMass),Bins(nbins));
// Add data and model to canvas
int col = (isMC ? kAzure+4 : kGreen+1);
data->plotOn(plot);
model.plotOn(plot,LineColor(col));
data->plotOn(plot);
model.paramOn(plot, Format(plotOpt, AutoPrecision(1)), Parameters(RooArgSet(cbBias, cbSigma, cbCut, cbPower, bwMean, bwWidth, expRate, nsig, nbkg)), Layout(0.15,0.45,0.80));
plot->getAttText()->SetTextSize(.03);
plot->SetTitle("");
plot->Draw();
// Print Fit Values
TLatex *tex = new TLatex();
tex->SetNDC();
tex->SetTextSize(.1);
tex->SetTextFont(132);
// tex->Draw();
tex->SetTextSize(0.057);
if(isMC) tex->DrawLatex(0.65, 0.75, "J/#psi #rightarrow e^{+}e^{-} MC");
else tex->DrawLatex(0.65, 0.75, "J/#psi #rightarrow e^{+}e^{-} data");
tex->SetTextSize(0.030);
tex->DrawLatex(0.645, 0.65, Form("BW Mean = %.2f GeV/c^{2}", bwMean.getVal()));
tex->DrawLatex(0.645, 0.60, Form("BW #sigma = %.2f GeV/c^{2}", bwWidth.getVal()));
c->Update();
c->SaveAs((outFilename + ".pdf").c_str());
c->SaveAs((outFilename + ".png").c_str());
// tablefile << Form(Outfile + "& $ %f $ & $ %f $ & $ %f $\\ \hline",cbBias.getVal(), cbSigma.getVal(), cbCut.getVal());
// Output workspace with model and data
RooWorkspace *w = new RooWorkspace("JPsieeMassScaleAndResolutionFit");
w->import(model);
w->import(*bdata);
w->writeToFile((outFilename + ".root").c_str());
TFile *tfileo = TFile::Open((outFilename + ".root").c_str(),"update");
fitres->Write();
tfileo->Close();
}