本文整理汇总了C++中TF1::GetHistogram方法的典型用法代码示例。如果您正苦于以下问题:C++ TF1::GetHistogram方法的具体用法?C++ TF1::GetHistogram怎么用?C++ TF1::GetHistogram使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TF1
的用法示例。
在下文中一共展示了TF1::GetHistogram方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Ifit
//.........这里部分代码省略.........
fmcsigfit->SetLineColor(4);
fmcsigfit->SetLineWidth(2);
f1->SetNpx(10000);
f1->SetParameters(par);
f1->SetLineWidth(2);
c10->cd(1);
fit_status = hsig->Fit(f1,"","",-1., 5.);
hsig->Draw();
f1->Draw("same");
if ( fit_status > 0 ) {
printf("fit signal template failed. QUIT \n");
return fitted;
}
if(para_index>0 && para_index<4){
double tmppar = f1->GetParameter(para_index);
f1->SetParameter(para_index, tmppar+para_sigma*f1->GetParError(para_index));
}
TF1 *fmcsig = (TF1*)f1->Clone();
TF1 *fmcsigcorr = (TF1*)f1->Clone();
fmcsig->SetNpx(10000);
fmcsigcorr->SetNpx(10000);
fmcsigfit->SetNpx(10000);
TCanvas *c101 = new TCanvas("c101","c101",1000,500);
c101->Divide(2,1);
c101->cd(1);
fmcsig->SetLineColor(1);
// fmcsig->Draw();
// f1->Draw("same");
TH1F *htmp1 = (TH1F*)fmcsig->GetHistogram();
// TH1F *htmp2 = (TH1F*)fmcsigcorr->GetHistogram();
TH2F *htmp2 = new TH2F("htmp2","",210, -1., 20., 100, 0., htmp1->GetMaximum()*1.25);
htmp2->SetNdivisions(505,"XY");
htmp2->SetXTitle("Iso");
htmp2->SetYTitle("A.U.");
htmp2->SetLineColor(1);
// htmp2->Draw();
// htmp1->Draw("same");
// htmp2->Add(htmp1,-1);
// htmp2->Divide(htmp1);
htmp2->GetXaxis()->SetRangeUser(-1., 10.);
htmp2->SetMinimum(-1.);
//htmp2->SetMaximum(1.5);
htmp2->Draw();
fmcsig->Draw("same");
// fmcsigcorr->Draw("same");
TLegend *tleg1 = new TLegend(0.5, 0.7, 0.93, 0.92);
tleg1->SetHeader("");
tleg1->SetFillColor(0);
tleg1->SetShadowColor(0);
tleg1->SetBorderSize(0);
tleg1->AddEntry(fmcsig,"Zee data","l");
//tleg1->AddEntry(fmcsigcorr,"corrected shape","l");
tleg1->AddEntry(fmcsigfit,"shape from data","l");
tleg1->Draw();
//return fitted;
示例2: fitOpt
/** Make Va1 response
@param n
@param B
@param dc
@param errors
@ingroup simple_script
*/
void
VA1Response(Int_t n=4, Float_t B=6, Float_t dc=.01, Bool_t errors=kFALSE,
Bool_t doFit=kFALSE)
{
gStyle->SetOptTitle(0);
gStyle->SetOptStat(0);
gStyle->SetOptFit(0);
gStyle->SetLabelFont(132, "xyz");
gStyle->SetTitleFont(132, "xyz");
gStyle->SetTitleSize(0.08, "y");
gStyle->SetTitleOffset(0.5, "y");
gStyle->SetTitleSize(0.06, "x");
gStyle->SetTitleOffset(0.7, "x");
TCanvas* c = new TCanvas("c", "c", 800, 500);
c->SetFillColor(0);
c->SetBorderMode(0);
c->SetBorderSize(0);
c->SetTopMargin(0.05);
c->SetRightMargin(0.05);
c->SetGridx();
c->SetGridy();
TF1* response = new TF1("response", "[0] * (1 - exp(-[1] * x))", 0, 1.4);
response->SetParameters(1, B);
response->SetParNames("A", "B");
response->SetLineColor(2);
TGraph* graph = 0;
if (n >= 2) {
if (errors) graph = new TGraphErrors(n);
else graph = new TGraph(n);
for (Int_t i = 0; i < n; i++) {
Float_t t = Float_t(i + 1) / n;
Float_t q = gRandom->Gaus(response->Eval(t), dc);
graph->SetPoint(i, t, q);
if (errors) ((TGraphErrors*)graph)->SetPointError(i, 0, dc);
}
}
response->Draw();
response->GetHistogram()->GetYaxis()->SetRangeUser(0, 1.05);
response->GetHistogram()->GetXaxis()->SetRangeUser(0, 1.1);
response->GetHistogram()->GetXaxis()->SetNdivisions(6, kTRUE);
response->GetHistogram()->GetYaxis()->SetNdivisions(10, kTRUE);
response->GetHistogram()->SetXTitle("t");
response->GetHistogram()->SetYTitle(Form("1-e^{-%3.1f t}", B));
if (graph) {
graph->Draw("P*");
TString fitOpt("E");
if (!errors) fitOpt.Append("W");
if (doFit) {
TF1* fit = new TF1("fit", "[0] * (1 - exp(-[1] * x))", 0, 1);
fit->SetParameters(.5, B/2);
fit->SetParNames("A", "B");
fit->SetLineColor(3);
graph->Fit("fit", fitOpt.Data());
graph->Fit("fit", fitOpt.Data());
std::cout << "Chi^2/NDF = " << fit->GetChisquare() << "/" << fit->GetNDF()
<< " = " << std::flush;
if (fit->GetNDF() == 0)
std::cout << " undefined!" << std::endl;
else
std::cout << (fit->GetChisquare() / fit->GetNDF()) << std::endl;
std::cout << "f(t) = "
<< fit->GetParameter(0) << "+/-" << fit->GetParError(0)
<< " * (1 - exp("
<< fit->GetParameter(1) << "+/-" << fit->GetParError(1)
<< " * t))" << std::endl;
}
}
c->Modified();
c->Update();
c->cd();
c->SaveAs("va1_response.png");
}
示例3: mk_sigaccanplots
//.........这里部分代码省略.........
TF1* fitfunccopy = (TF1 *) fitfunc->Clone(fitnamew.c_str());
if (fitfunc == NULL)
cout << "Can't get fit func\n";
else {
fitfunc->Delete();
fitfunccopy->SetLineWidth(3);
fitfunccopy->SetLineColor(kGreen + 3);
// fitfunc->SetLineStyle(3); // Dotted
}
float labsiz = 0.055;
h_GluinoHist_Fit->GetXaxis()->SetLabelFont(62);
h_GluinoHist_Fit->GetXaxis()->SetTitleFont(62);
h_GluinoHist_Fit->GetYaxis()->SetLabelFont(62);
h_GluinoHist_Fit->GetYaxis()->SetTitleFont(62);
h_GluinoHist_Fit->GetYaxis()->SetTitle("Gaussian width [GeV]");
float offset = 0.8;
if (tdrstyle == false) {
h_GluinoHist_Fit->GetXaxis()->SetTitleOffset(offset);
h_GluinoHist_Fit->GetYaxis()->SetTitleOffset(offset);
}
h_GluinoHist_Fit->GetXaxis()->SetTitle("Gluino mass [GeV]");
h_GluinoHist_Fit->GetXaxis()->SetTitleSize(labsiz);
h_GluinoHist_Fit->GetYaxis()->SetTitleSize(labsiz);
if (tdrstyle == false) {
float axsize = 0.04;
h_GluinoHist_Fit->GetXaxis()->SetLabelSize(axsize);
h_GluinoHist_Fit->GetYaxis()->SetLabelSize(axsize);
}
if (flavor.compare("113_223") == 0 && ptcut == "60")
h_GluinoHist_Fit->GetYaxis()->SetRangeUser(14.0, 50.0);
h_GluinoHist_Fit->Draw("APX"); // X eliminates error bars
// h_GluinoHist_Fit->Draw("AP");
// TH1 *fithist = (TH1 *) fitfunccopy->GetHistogram()->Clone(fitnamew.c_str());
TH1 *fithist = (TH1 *) fitfunccopy->GetHistogram()->Clone();
int fillcolor = kGreen + 2;
int fillstyle = 3013;
if (fithist != NULL) {
int numBins = fithist->GetNbinsX();
for (int cnt = 1; cnt <= numBins; ++cnt) {
setErr(fithist, cnt, flavor, "width");
}
fithist->SetFillColor(fillcolor);
fithist->SetFillStyle(fillstyle);
fithist->Draw("CE3SAME");
}
fitfunccopy->Draw("CSAME");
// h_GluinoHist_Fit->Draw("P"); // Draw points over fit line
leg->AddEntry(fitfunccopy, "Gaussian width", "L");
leg->AddEntry(fithist, "Uncertainty", "F");
leg->Draw();
tex->SetX(headpos);
tex->Draw();
tex2->Draw();
tex3->Draw();
tex3a->Draw();
if (tex4 != NULL)
tex4->Draw();
cGluinoFitsOpti->Write();
cGluinoFitsOpti->SaveAs((folder + "RPVwidth" +flavor + ptcut+uncert+postfix).c_str());
TCanvas * cGluinoFitsOpt2 = new TCanvas(("RPVacc_"+flavor +ptcut).c_str(), ("RPV_" + ptcut+"_"+cuts).c_str(), 800, 600);
// title="Acc. x Eff. for " + titlepart;
title= titlepart;
tex2->SetText(titpos,titly, title.c_str());
TLegend *leg2 = new TLegend(legx, 0.2, legx + 0.3, 0.4);
leg2->SetBorderSize(1);
示例4: fit
bool leptonic_fitter_algebraic::fit( const TLorentzVector& B, const TH1& BITF, const TF1& Beff,
const TLorentzVector& lep,
double MEX, double MEY, const TF1& dnuPDF )
{
if( _dbg > 19 ) cout<<"DBG20 Entered leptonic_fitter_algebraic::fit with B mass: "<<B.M()<<", l_m:"<<lep.M()<<", MET: "<<MEX<<" "<<MEY<<endl;
if( B.M() <= 0 ) throw std::runtime_error( "leptonic_fitter_algebraic was given a b-jet with an illegal (non-positive) mass!");
if( lep.M() < 0 ) throw std::runtime_error( "leptonic_fitter_algebraic was given a lepton with an illegal (negative) mass!");
_converged = _swapped = false;
_obsB = B;
_obsL = lep;
_BITF = &BITF;
_Beff = &Beff;
_dnuPDF = dnuPDF;
_b_m2 = B.M2();
double lep_b_angle = lep.Angle( B.Vect() );
double cos_lep_b = TMath::Cos( lep_b_angle );
double sin_lep_b = TMath::Sin( lep_b_angle );
double b_p = B.P();
double b_e = B.E();
_denom = b_e - cos_lep_b * b_p;
_lep_p = lep.P();
_x0 = - _W_m2 / ( 2 * _lep_p );
_y1 = - sin_lep_b * _x0 * b_p / _denom;
_x1_0 = _x0 * b_e / _denom - _y1*_y1 / _x0;
_Z2_0 = _x0*_x0 - _W_m2 - _y1*_y1;
if( _dbg > 219 ) cout<<"DBG220 lfa updated lepton with: "<<lv2str( lep )<<" -> x0:"<<_x0<<", y1: "<<_y1<<", x1_0: "<<_x1_0<<", Z2_0: "<<_Z2_0<<endl;
static double bnums[3];
bnums[0] = B.X();
bnums[1] = B.Y();
bnums[2] = B.Z();
TMatrixD bXYZ( 3, 1, bnums );
_R_T = rotation( 2, lep.Phi() ); // R_z^T
_R_T *= rotation( 1, lep.Theta() - 0.5*TMath::Pi() ); // R_z^T R_y^T
TMatrixD rotation_vect( _R_T, TMatrixD::kTransposeMult, bXYZ ); // R_y R_z
double* rotation_array = rotation_vect.GetMatrixArray();
double phi_x = - TMath::ATan2( rotation_array[2], rotation_array[1] );
if( _dbg > 99 ) cout<<"DBG100 lfa x rotation vector is:"<<rotation_array[0]<<" "<<rotation_array[1]<<" "<<rotation_array[2]<<" -> phi_x:"<<phi_x<<endl;
_R_T *= rotation( 0, - phi_x ); // R_z^T R_y^T R_x^T
// set up _Nu's non-zero elements so that \vec{nu} = Nu \vec{t} for any \vec{t} (since only t's 3nd component is used, and its always 1).
_Nu[0][2] = MEX;
_Nu[1][2] = MEY;
double iVarMET = TMath::Power( TMath::Max( 1., dnuPDF.GetHistogram()->GetRMS() ), -2 );
_invFlatVar[0][0] = _invFlatVar[1][1] = iVarMET; // set up the chi^2 distance with the right order of magnitude (generalizes to rotated covariance matrix)
if( _dbg > 209 ) cout<<"DBG210 lfa "<<dnuPDF.GetName()<<" --> iVarMET:"<<iVarMET<<endl;
// (re)define fit parameter, so all fits start off on an equal footing
_mini->SetPrintLevel( _minimizer_print_level );
_mini->Clear();
_mini->SetFunction( _functor );
leptonic_fitter_algebraic_object = this; // set the function in the functor pointing back to this object. Doubtfull that all this redirection is needed...
_mini->SetTolerance( _tolerance );
bool OK = _mini->SetLimitedVariable( 0, "sB", 1.0, 0.4, 0.1, 6.0 );
//bool OK = _mini->SetVariable( 0, "sB", 1.0, 0.4 );
if( ! OK ) {cerr<<"minimizer (@lfa) failed to SetVariable."<<endl; return false;}
// define 1 sigma in terms of the function
_mini->SetErrorDef( 0.5 ); // since this is a likelihood fit
// do the minimization
OK = _mini->Minimize();
if( _dbg > 19 && ( ! OK || _dbg > 59 ) ) cout<<"DBG INFO: initial fit @lfa returned OK: "<<OK<<", has status: "<<_mini->Status()<<endl;
_converged = OK; // use status somehow? depends on fitter?
// read parameters
const double *xs = _mini->X();
for( int ip = 0; ip < 1; ++ip ) _params[ ip ] = xs[ ip ];
// return all intermediate results to the minimum, in particular, the discriminant
calc_MLL( _params, true );
TMatrixD nu_vec( _Emat, TMatrixD::kMult, _tvec );
update_nu_and_decay_chain( nu_vec );
if( _dbg > 203 ) cout<<"DBG204 lfa finalized _genN: "<<lv2str(_genN)<<", _W: "<<lv2str(_W)<<", & _t: "<<lv2str(_T)<<endl;
_MLL = _mini->MinValue();
return true;
}