本文整理汇总了C++中TF1::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ TF1::Write方法的具体用法?C++ TF1::Write怎么用?C++ TF1::Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TF1
的用法示例。
在下文中一共展示了TF1::Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testRoot
void testRoot() {
//Fill a 1-D histogram from a parametric function
// To see the output of this macro, click begin_html <a href="gif/fillrandom.gif">here</a>. end_html
//Author: Rene Brun
TCanvas *c1 = new TCanvas("c1","The FillRandom example",200,10,700,900);
c1->SetFillColor(18);
TPad* pad1 = new TPad("pad1","The pad with the function",0.05,0.50,0.95,0.95,21);
TPad* pad2 = new TPad("pad2","The pad with the histogram",0.05,0.05,0.95,0.45,21);
pad1->Draw();
pad2->Draw();
pad1->cd();
gBenchmark->Start("fillrandom");
//
// A function (any dimension) or a formula may reference
// an already defined formula
//
TFormula* form1 = new TFormula("form1","abs(sin(x)/x)");
TF1* sqroot = new TF1("sqroot","x*gaus(0) + [3]*form1",0,10);
sqroot->SetParameters(10,4,1,20);
pad1->SetGridx();
pad1->SetGridy();
pad1->GetFrame()->SetFillColor(42);
pad1->GetFrame()->SetBorderMode(-1);
pad1->GetFrame()->SetBorderSize(5);
sqroot->SetLineColor(4);
sqroot->SetLineWidth(6);
sqroot->Draw();
TPaveLabel* lfunction = new TPaveLabel(5,39,9.8,46,"The sqroot function");
lfunction->SetFillColor(41);
lfunction->Draw();
c1->Update();
//
// Create a one dimensional histogram (one float per bin)
// and fill it following the distribution in function sqroot.
//
pad2->cd();
pad2->GetFrame()->SetFillColor(42);
pad2->GetFrame()->SetBorderMode(-1);
pad2->GetFrame()->SetBorderSize(5);
TH1F* h1f = new TH1F("h1f","Test random numbers",200,0,10);
h1f->SetFillColor(45);
h1f->FillRandom("sqroot",10000);
h1f->Draw();
c1->Update();
//
// Open a ROOT file and save the formula, function and histogram
//
TFile myfile("fillrandom.root","RECREATE");
form1->Write();
sqroot->Write();
h1f->Write();
gBenchmark->Show("fillrandom");
}
示例2: TestWrite
void TestWrite(const char *fname)
{
TFile fr(fname,"new");
TF1 *f = 0;
f = new TF1("f1","sin(x)"); f->Write();delete f;
f = new TF1("f2","sin(x)*x"); f->Write();delete f;
f = new TF1("f3","sin(x)+x"); f->Write();delete f;
f = new TF1("f4","tan(x)/x"); f->Write();delete f;
f = new TF1("f5","x*x*x"); f->Write();delete f;
f = new TF1("f6","xpol1"); f->SetParameters(1,2,3,4,5); f->Write();delete f;
f = new TF1("f7","xpol2"); f->SetParameters(1,2,3,4,5); f->Write();delete f;
f = new TF1("f8","xpol3"); f->SetParameters(1,2,3,4,5); f->Write();delete f;
fr.Close();
}
示例3: EfficiencyFit
void EfficiencyFit(TString inputdata="ROOTfiles/MCstudiesPP_Fine.root", TString label="PP_Fine"){
gStyle->SetTextSize(0.05);
gStyle->SetTextFont(42);
gStyle->SetPadRightMargin(0.043);
gStyle->SetPadLeftMargin(0.18);
gStyle->SetPadTopMargin(0.1);
gStyle->SetPadBottomMargin(0.145);
gStyle->SetTitleX(.0f);
TFile* inf = new TFile(inputdata.Data());
TH1D* hEff = (TH1D*)inf->Get("hEff");
TCanvas* c= new TCanvas(Form("c"),"",600,600);
hEff->Draw();
TF1 *myfit = new TF1("myfit","[0]+[1]*x+x*x*[2]+x*x*x*[3]+x*x*x*x*[4]", 7, 50);
//TF1 *myfit = new TF1("myfit","[0]+[1]*x+x*x*[2]+x*x*x*[3]", 7, 50);
//TF1 *myfit = new TF1("myfit","[0]+[1]*x+x*x*[2]", 7, 50);
hEff->Fit("myfit","L q","",7,50);
hEff->Fit("myfit","L q","",7,50);
hEff->Fit("myfit","L q","",7,50);
hEff->Fit("myfit","L m","",7,50);
double par0=myfit->GetParameter(0);
double par1=myfit->GetParameter(1);
double par2=myfit->GetParameter(2);
double par3=myfit->GetParameter(3);
double par4=myfit->GetParameter(4);
TString myEffWeight=Form("(%e+%e*Bpt+Bpt*Bpt*%e+Bpt*Bpt*Bpt*%e+Bpt*Bpt*Bpt*Bpt*%e)",par0,par1,par2,par3,par4);
std::cout<<myEffWeight<<std::endl;
c->SaveAs(Form("plotEffFit/%s.png", label.Data()));
TFile *fout=new TFile(Form("plotEffFit/%s.root", label.Data()),"recreate");
fout->cd();
hEff->Write();
myfit->Write();
fout->Close();
}
示例4: FitWithConstant
void FitWithConstant(TH1D* h1, TFile *out)
{
Double_t fitRangeLow = 0.;
Double_t fitRangeHigh = .4;
TF1 *f = new TF1("f","[0]", fitRangeLow, fitRangeHigh);
Int_t binLow = h1->FindBin(fitRangeLow);
Int_t binHigh = h1->FindBin(fitRangeHigh);
cout<<"\t\t********************Fitting with a constant value********************"<<endl<<endl;;
h1->Fit(f, "R0");
TString fitName = h1->GetName();
fitName += "Fit";
f->SetName(fitName);
f->SetTitle(fitName);
// TFile out("Compare.root","update");
TDirectory *dir = out->GetDirectory("Fit");
if(!dir) dir = out->mkdir("Fit");
dir->cd();
// f->SetDirectory(0);
f->Write(f->GetName(), TObject::kOverwrite);
// out->Close();
}
示例5: fitBjetJES
//.........这里部分代码省略.........
}
if(ppPbPb){
for(int i=0;i<tB->GetEntries();i++){
tB->GetEntry(i);
if(fabs(jtetaB)<2 && binB>=cbinlo && binB<cbinhi && abs(refparton_flavorForBB)==5)
hB->Fill(refptB,jtptB/refptB,weightB);
}
for(int i=0;i<tC->GetEntries();i++){
tC->GetEntry(i);
if(fabs(jtetaC)<2 && binC>=cbinlo && binC<cbinhi && abs(refparton_flavorForBC)==4)
hC->Fill(refptC,jtptC/refptC,weightC);
}
}
hL->SetMinimum(0.);
hL->SetLineColor(kBlue);
hB->SetLineColor(kRed);
hC->SetLineColor(kGreen);
hL->SetMarkerColor(kBlue);
hB->SetMarkerColor(kRed);
hC->SetMarkerColor(kGreen);
//hL->SetMarkerStyle(4);
//hB->SetMarkerStyle(4);
//hC->SetMarkerStyle(4);
hL->SetXTitle("genJet p_{T} (GeV/c)");
hL->SetYTitle("<reco p_{T} / gen p_{T} >");
hL->GetXaxis()->SetRangeUser(50.,199.999);
hL->GetYaxis()->SetRangeUser(0.5,1.05);
TCanvas *c1=new TCanvas("c1","c1",800,600);
c1->SetGridx(1);
c1->SetGridy(1);
hL->Draw("e1");
hB->Draw("e1,same");
hC->Draw("e1,same");
TLegend *leg=new TLegend(0.4,0.15,0.9,0.45);
leg->SetBorderSize(0);
leg->SetFillStyle(0);
if(ppPbPb&&cbinlo==0&&cbinhi==40)leg->SetHeader("Pythia+Hydjet, 0-100%");
leg->AddEntry(hL,"Inclusive jets","pl");
leg->AddEntry(hC,"c-jets","pl");
leg->AddEntry(hB,"b-jets","pl");
leg->Draw();
TCanvas *c2=new TCanvas("c2","c2",1);
/*
TH1F *hL2 = (TH1F*)hL->Clone("hL2");
TH1F *hB2 = (TH1F*)hB->Clone("hB2");
hL2->Add(hB2,-1);
hL2->Draw();
*/
TH1F *hcorr = new TH1F("hcorr","hcorr",250,50,300);
hcorr->Sumw2();
for(int i=0;i<hL->GetNbinsX();i++){
cout<<" b resp "<<hB->GetBinContent(i+1)<<endl;
cout<<" l resp "<<hL->GetBinContent(i+1)<<endl;
cout<<" l offset "<<1.-hL->GetBinContent(i+1)<<endl;
cout<<" corrected b resp "<<hB->GetBinContent(i+1)+1.-hL->GetBinContent(i+1)<<endl;
float jesOffset = 1.-hL->GetBinContent(i+1);
hcorr->SetBinContent(i+1,hB->GetBinContent(i+1)+jesOffset);
hcorr->SetBinError(i+1,sqrt(hB->GetBinError(i+1)*hB->GetBinError(i+1)+hL->GetBinError(i+1)*hL->GetBinError(i+1)));
}
hcorr->SetMinimum(0.5);
hcorr->SetMaximum(1.1);
hcorr->SetLineColor(kRed);
hcorr->SetMarkerColor(kRed);
hcorr->SetMarkerStyle(4);
hcorr->Draw();
TF1 *fCorr = new TF1("fCorr","[0]+[1]*log(x)+[2]*log(x)*log(x)",50,300);
fCorr->SetLineWidth(1);
fCorr->SetLineColor(kBlue);
hcorr->Fit(fCorr);
TFile *fout;
if(ppPbPb) fout =new TFile(Form("bJEShistos/bJetScale_PbPb_Cent_fineBin_%d_%d.root",cbinlo,cbinhi),"recreate");
else fout =new TFile("bJEShistos/bJetScale_PP_fineBin.root","recreate");
hcorr->Write();
fCorr->Write();
fout->Close();
}
示例6: histoLoader_new
//.........这里部分代码省略.........
std::cout << "RMS1_" << i << " = " << RMS1 << std::endl;
std::cout << "RMS2_" << i << " = " << RMS2 << std::endl;
if( RMS1 > RMS2 ){
thetaRMS[i] = RMS2;
} else thetaRMS[i] = RMS1;
inFile->Close();
}
else break;
i++;
}
TFile *outFile = new TFile(outfileName.c_str(), "RECREATE");
Double_t x_data[4] = {2.54 / 4, 2.54 / 2, 2.54*3/4, 2.54};
Double_t xerr[4] = {0.005, 0.005, 0.005, 0.005};
Double_t yerr[4] = {0.197, 0.272, 0.351, 0.136};
Double_t x0[20] = {0};
Double_t y0[20] = {0};
Double_t x1[20] = {0};
Double_t y1[20] = {0};
Double_t x2[20] = {0};
Double_t y2[20] = {0};
int j=1;
for (Double_t h=0.15; j<20; j++) {
x0[j] = h;
y0[j] = moliFunc(x0[j], p0);
h+=0.15;
std::cout << "x0[" << j << "] = " << x0[j] << std::endl;
std::cout << "y0[" << j << "] = " << y0[j] << std::endl;
}
int k=1;
for (Double_t h=0.15; k<20; k++) {
x1[k] = h;
y1[k] = moliFunc(x1[k], p1);
h+=0.15;
std::cout << "x1[" << k << "] = " << x1[k] << std::endl;
std::cout << "y1[" << k << "] = " << y1[k] << std::endl;
}
int l=1;
for (Double_t h=0.15; l<20; l++) {
x2[l] = h;
y2[l] = moliFunc(x2[l], p2);
h+=0.15;
std::cout << "x2[" << l << "] = " << x2[l] << std::endl;
std::cout << "y2[" << l << "] = " << y2[l] << std::endl;
}
TGraph *moliGraph0 = new TGraph(20, x0, y0);
TGraph *moliGraph1 = new TGraph(20, x1, y1);
TGraph *moliGraph2 = new TGraph(20, x2, y2);
TGraphErrors *dataGraph = new TGraphErrors(4, x_data, thetaRMS, xerr, yerr);
TF1 *moliFit = new TF1("moliFit", moliFunc_Fit, 0, 10, 1);
moliFit->SetLineColor(6);
moliFit->SetLineWidth(2);
moliFit->SetParameters(0, 13.6);
moliFit->SetParNames("Constant");
moliFit->SetParLimits(0, 0, 30);
// moliFit->SetParLimits(1, 0, 0.25);
dataGraph->Fit("moliFit");
std::cout << "thetaRMS[0] = " << thetaRMS[0] << std::endl;
std::cout << "thetaRMS[1] = " << thetaRMS[1] << std::endl;
std::cout << "thetaRMS[2] = " << thetaRMS[2] << std::endl;
std::cout << "thetaRMS[3] = " << thetaRMS[3] << std::endl;
//std::cout << "thetaRMS[4] = " << thetaRMS[4] << std::endl;
moliGraph0->SetLineColor(2);
moliGraph0->SetLineWidth(1.5);
moliGraph1->SetLineColor(8);
moliGraph1->SetLineWidth(1.5);
moliGraph2->SetLineColor(9);
moliGraph2->SetLineWidth(1.5);
dataGraph ->SetMarkerStyle(22);
moliGraph0->Draw("AC");
moliGraph1->Draw("PC");
moliGraph2->Draw("PC");
dataGraph->Draw("P");
//moliFit->Draw("*");
TLegend *leg = new TLegend(0.1, 0.7, 0.48, 0.9);
leg->SetHeader("Legend");
// gStyle->SetLegendFillColor(0);
leg->AddEntry(moliGraph1, "Moliere Distribution for p = 222 MeV/c", "LP");
leg->AddEntry(moliGraph0, "Moliere Distribution for p = 248.5 MeV/c", "LP");
leg->AddEntry(moliGraph2, "Moliere Distribution for p = 275 MeV/c", "LP");
leg->AddEntry(dataGraph, "The angular RMS for varying Pb thicknesses", "LP");
leg->AddEntry(moliFit, "The angular RMS data fit to the Moliere Distribution", "LP");
leg->Draw();
moliGraph0->Write();
moliGraph1->Write();
moliGraph2->Write();
moliFit->Write();
dataGraph->Write();
outFile->Close();
}
示例7: GeneralCorrectionFunction
TF1* GeneralCorrectionFunction(
double ChannelRangeMin, double ChannelRangeMax,double ChannelPeakPos ,
TH2D *h2DInputForCorrection ,
int LineIndex,
TString InputType="T10DeriMaxEnergy",
TString CorrNumber="1",
double XRangeMin=0, double XRangeMax=300,
TString FitFuncCorr="pol2",
double FitCorrRangeMin=10, double FitCorrRangeMax= 270,
double TresholdForCorrection=10,
TString FitFuncSlicesString="gaus(0)+[3]+gaus(4)"
)
{
h2DInputForCorrection->GetYaxis()->SetRangeUser(ChannelRangeMin,ChannelRangeMax);
char buf[60];
sprintf(buf, "hMaxCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex);
TH1D *hMaxPosManually=new TH1D(buf,"",h2DInputForCorrection->GetNbinsX(),h2DInputForCorrection->GetXaxis()->GetXmin(),h2DInputForCorrection->GetXaxis()->GetXmax());
sprintf(buf, "hMaxFitCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex);
TH1D *hMaxPosManuallyFit=new TH1D(buf,"",h2DInputForCorrection->GetNbinsX(),h2DInputForCorrection->GetXaxis()->GetXmin(),h2DInputForCorrection->GetXaxis()->GetXmax());
sprintf(buf, "hGausSigmaCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex);
TH1D *hGausSigmaManually=new TH1D(buf,"",h2DInputForCorrection->GetNbinsX(),h2DInputForCorrection->GetXaxis()->GetXmin(),h2DInputForCorrection->GetXaxis()->GetXmax());
for(int binX = h2DInputForCorrection->GetXaxis()->FindBin(XRangeMin);binX <= h2DInputForCorrection->GetXaxis()->FindBin(XRangeMax);binX++)
//for(int binX = h2DInputForCorrection->GetXaxis()->FindBin(200);binX <= h2DInputForCorrection->GetXaxis()->FindBin(200);binX++)
{
TH1D *hProfileY =h2DInputForCorrection->ProjectionY("_py",binX,binX);
double MaxValue=hProfileY->GetBinCenter(hProfileY->GetMaximumBin());
//hMaxPosManually->SetBinContent(binX, MaxValue);
//h2DInputForCorrection
//cout <<hProfileY->GetEntries()<<endl;
//TF1* FitFuncSlices = new TF1("FitFuncSlices","gaus(0)+[3]",MaxValue-20,MaxValue+20);
//cout << TMath::Max(MaxValue-20,double(ChannelRangeMin)) << "\t" << TMath::Min(MaxValue+20,double(ChannelRangeMax)) << "\t"<<endl;
TF1* FitFuncGausSlices = new TF1("FitFuncGausSlices","gaus(0)",TMath::Max(MaxValue-20,double(ChannelRangeMin)),TMath::Min(MaxValue+20,double(ChannelRangeMax)));
FitFuncGausSlices->SetParameters(hProfileY->GetBinContent(hProfileY->GetMaximumBin()),MaxValue,4);
hProfileY->Fit(FitFuncGausSlices,"RNIQ");
TF1* FitFuncSlices = new TF1("FitFuncSlices",FitFuncSlicesString.Data(),TMath::Max(MaxValue-3*FitFuncGausSlices->GetParameter(2),double(ChannelRangeMin)),TMath::Min(MaxValue+3*FitFuncGausSlices->GetParameter(2),double(ChannelRangeMax)));
FitFuncSlices->SetParameters(FitFuncGausSlices->GetParameter(0),FitFuncGausSlices->GetParameter(1),FitFuncGausSlices->GetParameter(2),10,10,FitFuncGausSlices->GetParameter(1)-5,5);
FitFuncSlices->SetParLimits(0,FitFuncGausSlices->GetParameter(0)*0.8,FitFuncGausSlices->GetParameter(0)*1.5);
FitFuncSlices->SetParLimits(1,TMath::Max(FitFuncGausSlices->GetParameter(1)-10,double(ChannelRangeMin)),TMath::Min(FitFuncGausSlices->GetParameter(1)+10,double(ChannelRangeMax)));
FitFuncSlices->SetParLimits(2,0,FitFuncGausSlices->GetParameter(2)*2);
FitFuncSlices->SetParLimits(3,0,500);
FitFuncSlices->SetParLimits(4,0,FitFuncGausSlices->GetParameter(0)*0.3);
FitFuncSlices->SetParLimits(5,TMath::Max(FitFuncGausSlices->GetParameter(1)-10,double(ChannelRangeMin)),TMath::Min(MaxValue-1,double(ChannelRangeMax)));
FitFuncSlices->SetParLimits(6,0,10);
hProfileY->Fit(FitFuncSlices,"RINQ");
//hProfileY->DrawCopy();
//cout <<MaxValue<<" " << FitFuncSlices->GetParameter(1) << " " << FitFuncSlices->GetParError(1) <<endl;
//cout <<MaxValue<<" " << FitFuncSlices->GetParameter(1) << " " << FitFuncSlices->GetMaximumX() <<endl;
hMaxPosManually->SetBinContent(binX, (FitFuncSlices->GetParameter(1))/ChannelPeakPos);
hMaxPosManually->SetBinError(binX, FitFuncSlices->GetParError(1)/ChannelPeakPos);
hGausSigmaManually->SetBinContent(binX, FitFuncSlices->GetParameter(2));
hGausSigmaManually->SetBinError(binX, FitFuncSlices->GetParError(2));
if(FitFuncSlices->GetParameter(2)<TresholdForCorrection && FitFuncSlices->GetParError(2)<5)
{
hMaxPosManuallyFit->SetBinContent(binX, (FitFuncSlices->GetParameter(1))/ChannelPeakPos);
hMaxPosManuallyFit->SetBinError(binX, FitFuncSlices->GetParError(1)/ChannelPeakPos);
}
//hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->SetBinError(binX, FitFuncSlices->GetParameter(2)/ChannelPeakPos);
hProfileY->Delete();
//cin.ignore();
}
//write histos to file
//sprintf(buf, "hMaxCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex);
hMaxPosManually->Write(0,TObject::kOverwrite);
//sprintf(buf, "hGausSigmaCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex);
hGausSigmaManually->Write(0,TObject::kOverwrite);
hMaxPosManuallyFit->Write(0,TObject::kOverwrite);
sprintf(buf, "funcCorr%s_%sNorm_%d",CorrNumber.Data(),InputType.Data(),LineIndex);
//fit corr function and write it to file
TF1 *funcCorrNorm = new TF1(buf,FitFuncCorr.Data(),FitCorrRangeMin,FitCorrRangeMax);
funcCorrNorm->SetParameters(1,0,-0);
funcCorrNorm->SetParLimits(0,0.8,1);
//funcCorrNorm->SetParLimits(2,-1E5,0);
//if(LineIndex==2)
// hMaxPosManuallyFit->Fit(funcCorrNorm,"RBI");
//else
hMaxPosManuallyFit->Fit(funcCorrNorm,"RBQI");
sprintf(buf, "funcCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex);
TF1 *funcCorr = new TF1(buf,FitFuncCorr.Data(),FitCorrRangeMin,FitCorrRangeMax);
for(int i= 0; i<funcCorr->GetNpar();i++)
{
funcCorr->SetParameter(i,funcCorrNorm->GetParameter(i)*ChannelPeakPos);
}
//sprintf(buf, "funcCorr%s_%sNorm_%d",CorrNumber.Data(),InputType.Data(),LineIndex);
funcCorrNorm->Write(0,TObject::kOverwrite);
//sprintf(buf, "funcCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex);
funcCorr->Write(0,TObject::kOverwrite);
h2DInputForCorrection->GetYaxis()->UnZoom();
return funcCorr;
}
示例8: studyBinZero
//.........这里部分代码省略.........
funcRatioVtxCutZ->SetLineWidth(2);
funcRatioVtxCutZ->SetLineColor(kRed);
const Double_t meanRatioVtxCutZ = funcRatioVtxCutZ->GetParameter(0);
const Double_t ratioNevtVtxCutZ = numEvtsTriggerSelVtxCutZ > 0 ? numEvtsTriggerSelVtxCut / numEvtsTriggerSelVtxCutZ : -1.;
TH1D* hRatioPileUp = new TH1D(*hSpectraTriggerSelVtxCutZPileUpRej);
hRatioPileUp->SetName("hRatioPileUp");
setupHist(hRatioPileUp, kBlack, "MB & vtx & #it{z} vtx & pile-up / MB & vtx & #it{z} vtx");
hRatioPileUp->GetYaxis()->SetTitle("1/#it{N}_{evt} d#it{N}/d#it{p}_{T}^{gen} ratio");
hRatioPileUp->Divide(hRatioPileUp, hSpectraTriggerSelVtxCutZ, 1., 1., "B");
/*
TF1* funcRatioPileUp = new TF1("funcRatioPileUp", "pol0",
0.15, hRatioPileUp->GetXaxis()->GetBinUpEdge(hSpectraTriggerSelVtxCutZPileUpRej->FindLastBinAbove(0)));
hRatioPileUp->Fit(funcRatioPileUp, "N");*/
ClearTitleFromHistoInCanvas(canvSpectra);
TCanvas* canvRatioVtx = new TCanvas("canvRatioVtx", "Ratio vertex", 760, 420);
canvRatioVtx->SetLogx();
canvRatioVtx->SetGrid(0, 1);
SetCanvasMargins(canvRatioVtx);
hRatioVtxCut->Draw();
funcRatioVtxCut->Draw("same");
TLegend* leg2 = new TLegend(0.22, 0.7, drawPileUp ? 0.87 : 0.72, 0.9);
leg2->SetHeader(Form("MC pp #sqrt{s}=7 TeV, inclusive, %s", etaRange.Data()));
leg2->AddEntry(hRatioVtxCut, "", "l");
SetupLegend(leg2);
leg2->SetMargin(0.1);
leg2->Draw("same");
ClearTitleFromHistoInCanvas(canvRatioVtx);
TCanvas* canvRatioOther = new TCanvas("canvRatioOther", "Ratio others", 760, 420);
canvRatioOther->SetLogx();
canvRatioOther->SetGrid(0, 1);
SetCanvasMargins(canvRatioOther);
hRatioVtxCutZ->Draw();
if (drawPileUp)
hRatioPileUp->Draw("same");
TLegend* leg3 = new TLegend(0.22, drawPileUp ? 0.63 : 0.7, drawPileUp ? 0.87 : 0.72, 0.9);
leg3->SetHeader(Form("MC pp #sqrt{s}=7 TeV, inclusive, %s", etaRange.Data()));
leg3->AddEntry(hRatioVtxCutZ, "", "l");
if (drawPileUp)
leg3->AddEntry(hRatioPileUp, "", "l");
SetupLegend(leg3);
leg3->SetMargin(0.1);
leg3->Draw("same");
ClearTitleFromHistoInCanvas(canvRatioOther);
printf("meanRatioVtxCut %f <-> ratioNevtVtxCut %f => meanRatioVtxCutZ/ratioNevtVtxCutZ - 1 = %f\nmeanRatioVtxCutZ %f <-> ratioNevtVtxCutZ %f\n",
meanRatioVtxCut, ratioNevtVtxCut, doubleRatioMinusOne, meanRatioVtxCutZ, ratioNevtVtxCutZ);
TNamed* settings = new TNamed(
Form("Settings: Data file \"%s\", lowerEta %.2f, uppEta %.2f, lowerCentrality %.3f, upperCentrality %.3f, doubleRatioMinusOne %.4f\n",
pathNameData.Data(), etaLow, etaUp, lowerCentrality, upperCentrality, doubleRatioMinusOne), "");
// Save results to file
TString saveFileName = pathNameData;
saveFileName = Form("%s_binZeroStudy.root", saveFileName.ReplaceAll(".root", "").Data());
TFile *saveFile = TFile::Open(saveFileName.Data(), "RECREATE");
saveFile->cd();
hSpectraTriggerSel->Write();
hSpectraTriggerSelVtxCut->Write();
hSpectraTriggerSelVtxCutZ->Write();
hSpectraTriggerSelVtxCutZPileUpRej->Write();
hRatioVtxCut->Write();
hRatioVtxCutZ->Write();
hRatioPileUp->Write();
funcRatioVtxCut->Write();
funcRatioVtxCutZ->Write();
canvSpectra->Write();
canvRatioVtx->Write();
canvRatioOther->Write();
settings->Write();
saveFile->Close();
TString temp = saveFileName;
canvRatioVtx->SaveAs(Form("%s", temp.ReplaceAll(".root", "_ratioVtx.pdf").Data()));
temp = saveFileName;
canvRatioOther->SaveAs(Form("%s", temp.ReplaceAll(".root", "_ratioOther.pdf").Data()));
PrintSettingsAxisRangeForMultiplicityAxisForMB();
return 0;
}
示例9: TCanvas
//.........这里部分代码省略.........
mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2));
//mass->SetParError(0,f->GetParError(0));
//mass->SetParError(1,f->GetParError(1));
//mass->SetParError(2,f->GetParError(2));
mass->SetLineColor(2);
h->SetXTitle("m_{#mu#muK} (GeV/c^{2})");
h->SetYTitle("Entries / (5 MeV/c^{2})");
h->GetXaxis()->CenterTitle();
h->GetYaxis()->CenterTitle();
h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y");
h->GetXaxis()->SetTitleOffset(1.3);
h->GetYaxis()->SetTitleOffset(1.8);
h->GetXaxis()->SetLabelOffset(0.007);
h->GetYaxis()->SetLabelOffset(0.007);
h->GetXaxis()->SetTitleSize(0.045);
h->GetYaxis()->SetTitleSize(0.045);
h->GetXaxis()->SetTitleFont(42);
h->GetYaxis()->SetTitleFont(42);
h->GetXaxis()->SetLabelFont(42);
h->GetYaxis()->SetLabelFont(42);
h->GetXaxis()->SetLabelSize(0.04);
h->GetYaxis()->SetLabelSize(0.04);
h->SetMarkerSize(0.8);
h->SetMarkerStyle(20);
h->SetStats(0);
h->Draw("e");
background->Draw("same");
mass->SetRange(minhisto,maxhisto);
mass->Draw("same");
mass->SetLineStyle(2);
mass->SetFillStyle(3004);
mass->SetFillColor(2);
f->Draw("same");
Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass;
Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0);
TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC");
leg->SetBorderSize(0);
leg->SetTextSize(0.04);
leg->SetTextFont(42);
leg->SetFillStyle(0);
leg->AddEntry(h,"Data","pl");
leg->AddEntry(f,"Fit","l");
leg->AddEntry(mass,"Peaking BG","f");
leg->AddEntry(background,"Combinatorial","l");
leg->Draw("same");
TLatex* texCms = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary");
texCms->SetNDC();
texCms->SetTextAlign(12);
texCms->SetTextSize(0.04);
texCms->SetTextFont(42);
texCms->Draw();
TLatex* texCol;
if(collisionsystem=="pp"||collisionsystem=="PP") texCol= new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV","pp"));
else texCol= new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV","PbPb"));
texCol->SetNDC();
texCol->SetTextAlign(32);
texCol->SetTextSize(0.04);
texCol->SetTextFont(42);
texCol->Draw();
TLatex* tex;
tex = new TLatex(0.22,0.78,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax));
tex->SetNDC();
tex->SetTextFont(42);
tex->SetTextSize(0.04);
tex->SetLineWidth(2);
tex->Draw();
if(centMax>0){
TString texper="%";
tex = new TLatex(0.22,0.71,Form("Centrality %.0f-%.0f%s",centMin,centMax,texper.Data()));//0.2612903,0.8425793
tex->SetNDC();
tex->SetTextColor(1);
tex->SetTextFont(42);
tex->SetTextSize(0.045);
tex->SetLineWidth(2);
tex->Draw();
}
tex = new TLatex(0.22,0.83,"|y| < 2.4");
tex->SetNDC();
tex->SetTextFont(42);
tex->SetTextSize(0.04);
tex->SetLineWidth(2);
tex->Draw();
total=f;
h->Write();
f->Write();
if(!isPbPb) c->SaveAs(Form("plotNP/BMass%s_%d.pdf",collisionsystem.Data(),count));
else c->SaveAs(Form("plotNP/BMass%s_%.0f_%.0f_%d.pdf",collisionsystem.Data(),centMin,centMax,count));
return mass;
}
示例10: makeInvMassHistosNoBGKK
//.........这里部分代码省略.........
fit->SetParLimits(1, 0.82, 0.98);
//}
//fit->SetParLimits(2, 0.005, 0.15);
fit->FixParameter(2, 0.042);
fit->FixParameter(3, meanPT);
//fit->SetParLimits(4, 0.05, 0.2);
fit->FixParameter(4, 0.100001);
fit->SetLineColor(2);
printf("%s\n", fit->GetName());
histos[i]->Fit(Form("fitPTbin%d00particle%d", nfile*2+1, i), "BRIM", "SAME");
TVirtualFitter *fitter = TVirtualFitter::GetFitter();
histos[i]->SetStats(1);
histos[i]->Draw();
gPad->Update();
pad->Update();
st = (TPaveStats*)histos[i]->FindObject("stats");
st->SetX1NDC(0.524);
st->SetY1NDC(0.680);
st->SetX2NDC(0.884);
st->SetY2NDC(0.876);
//fit->Draw("SAME");
//histos[i]->Draw();
gPad->Update();
pad->Update();
printf("\n");
diffHistos[i] = (TH1D*)histos[i]->Clone(Form("diffPTbin%d00particl%d", nfile*2+1, i));
diffHistos[i]->Add(fit, -1);
diffCanvas[i]->cd(nfile+1);
diffHistos[i]->Draw("HIST E");
diffHistos[i]->Write();
//counting bins
Float_t integral = histos[i]->Integral(1, 500)*500.0;
//integrals << integral <<" \n";
histos[i]->Write();
fit->Write();
//Do mass and width vs. pT plots just for K*0
if(i==PARTICLE_NUM){
mass = fit->GetParameter(1);
massError = fit->GetParError(1);
collWidth = fit->GetParameter(2);
collWidthError = fit->GetParError(2);
width = Gamma(mass, collWidth);
kstar0mass->SetBinContent(nfile+1, mass);
kstar0mass->SetBinError(nfile+1, massError);
kstar0width->SetBinContent(nfile+1, width);
Double_t widthError = TMath::Sqrt((GammaDerivative(mass)**2)*fitter->GetCovarianceMatrixElement(1,1) + fitter->GetCovarianceMatrixElement(2,2) + 2.0*GammaDerivative(mass)*fitter->GetCovarianceMatrixElement(1,2));
kstar0width->SetBinError(nfile+1, widthError);
kstar0collWidth->SetBinContent(nfile+1, collWidth);
kstar0collWidth->SetBinError(nfile+1, collWidthError);
kstar0decWidth->SetBinContent(nfile+1, width - collWidth);
Double_t decWidthError = TMath::Sqrt((GammaDerivative(mass)**2)*fitter->GetCovarianceMatrixElement(1,1));
kstar0decWidth->SetBinError(nfile+1, decWidthError);
if(nfile==4){
TCanvas *singlecanvas = new TCanvas("singlecanvas", "singlecanvas", 0,0,600,600);
示例11: TCanvas
//.........这里部分代码省略.........
f->FixParameter(2,f->GetParameter(2));
f->FixParameter(7,f->GetParameter(7));
f->FixParameter(8,f->GetParameter(8));
h->Fit(Form("f%d",count),"q","",5,6);
h->Fit(Form("f%d",count),"q","",5,6);
f->ReleaseParameter(1);
h->Fit(Form("f%d",count),"L q","",5,6);
h->Fit(Form("f%d",count),"L q","",5,6);
h->Fit(Form("f%d",count),"L q","",5,6);
h->Fit(Form("f%d",count),"L m","",5,6);
h->SetMarkerSize(0.8);
h->SetMarkerStyle(20);
cout <<h->GetEntries()<<endl;
// function for background shape plotting. take the fit result from f
TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x");
background->SetParameter(0,f->GetParameter(3));
background->SetParameter(1,f->GetParameter(4));
background->SetParameter(2,f->GetParameter(5));
background->SetParameter(3,f->GetParameter(6));
background->SetLineColor(4);
background->SetRange(5,6);
background->SetLineStyle(2);
// function for signal shape plotting. take the fit result from f
TF1 *Bkpi = new TF1(Form("fBkpi%d",count),"[0]*("+iNP+")");
Bkpi->SetParameter(0,f->GetParameter(5));
Bkpi->SetLineColor(kGreen+1);
Bkpi->SetFillColor(kGreen+1);
// Bkpi->SetRange(5.00,5.28);
Bkpi->SetRange(5.00,6.00);
Bkpi->SetLineStyle(1);
Bkpi->SetFillStyle(3004);
// function for signal shape plotting. take the fit result from f
TF1 *mass = new TF1(Form("fmass%d",count),"[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))");
mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8));
mass->SetParError(0,f->GetParError(0));
mass->SetParError(1,f->GetParError(1));
mass->SetParError(2,f->GetParError(2));
mass->SetParError(7,f->GetParError(7));
mass->SetParError(8,f->GetParError(8));
mass->SetLineColor(2);
mass->SetLineStyle(2);
// cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl;
h->SetMarkerStyle(24);
h->SetStats(0);
h->Draw("e");
h->SetXTitle("M_{B} (GeV/c^{2})");
h->SetYTitle("Entries / (20 MeV/c^{2})");
h->GetXaxis()->CenterTitle();
h->GetYaxis()->CenterTitle();
h->SetTitleOffset(1.5,"Y");
h->SetAxisRange(0,h->GetMaximum()*1.2,"Y");
Bkpi->Draw("same");
background->Draw("same");
mass->SetRange(5,6);
mass->Draw("same");
mass->SetLineStyle(2);
mass->SetFillStyle(3004);
mass->SetFillColor(2);
f->Draw("same");
hraw->Draw("same");
double yield = mass->Integral(5,6)/0.02;
double yieldErr = mass->Integral(5,6)/0.02*mass->GetParError(0)/mass->GetParameter(0);
// Draw the legend:)
TLegend *leg = myLegend(0.50,0.5,0.86,0.89);
leg->AddEntry(h,"CMS Preliminary","");
leg->AddEntry(h,"pPb #sqrt{s_{NN}} = 5.02 TeV","");
leg->AddEntry(h,Form("%.0f < p_{T}^{B} < %.0f GeV/c",ptmin,ptmax),"");
leg->AddEntry(h,"Data","pl");
leg->AddEntry(f,"Fit","l");
leg->AddEntry(mass,"Signal","f");
leg->AddEntry(background,"Combinatorial Background","l");
leg->AddEntry(Bkpi,"Non-prompt J/#psi","f");
leg->Draw();
TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50);
leg2->AddEntry(h,"B meson","");
leg2->AddEntry(h,Form("M_{B} = %.2f #pm %.2f MeV/c^{2}",mass->GetParameter(1)*1000.,mass->GetParError(1)*1000.),"");
leg2->AddEntry(h,Form("N_{B} = %.0f #pm %.0f", yield, yieldErr),"");
leg2->Draw();
if(ispPb)c->SaveAs(Form("../ResultsBplus/BMass-%d.pdf",count));
else c->SaveAs(Form("../ResultsBplus_pp/BMass-%d.pdf",count));
h->Write();
hMC->Write();
f->Write();
background->Write();
Bkpi->Write();
mass->Write();
hraw->Write();
return mass;
}
示例12: DoTDeriMax1090Correction
//.........这里部分代码省略.........
FitFuncSlices->SetParLimits(0,0,10000);
FitFuncSlices->SetParLimits(1,MaxValue-10,MaxValue+10);
FitFuncSlices->SetParLimits(2,0,10);
FitFuncSlices->SetParLimits(3,0,100);
hProfileY->Fit(FitFuncSlices,"RNQ");
cout <<MaxValue<<" " << FitFuncSlices->GetParameter(1) << " " << FitFuncSlices->GetParError(1) <<endl;
hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->SetBinContent(binX, FitFuncSlices->GetParameter(1));
hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->SetBinError(binX, FitFuncSlices->GetParError(1));
}
hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->GetYaxis()->SetRangeUser(ChannelPeakPos-100,ChannelPeakPos+50);
hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->GetXaxis()->SetRangeUser(-0.05,0.9);
TF1 * funcCorrConst = new TF1("funcCorrConst","pol0",-0.03,0.03);
funcCorrConst->SetLineColor(kRed);
TF1 * funcCorrPol = new TF1("funcCorrPol",PolPiecewise,-0.05,0.9,6);
funcCorrPol->SetLineColor(kBlue);
funcCorrPol->SetParameter(0,0.04);
funcCorrPol->SetParameter(1,ChannelPeakPos);
hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->Fit(funcCorrConst,"R");
hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->Fit(funcCorrPol,"R+");
TCanvas* can2=new TCanvas();
gPad->SetLogz();
hSpectrumTDeriMax1090Rel_EnergyChannel->Draw("colz");
funcCorrPol->DrawCopy("same");
for(int i = 7;i>0;i--)
funcCorrPol->SetParameter(i,funcCorrPol->GetParameter(i)/funcCorrPol->GetParameter(1));
funcCorrPol->Print();
char buf[20];
sprintf(buf, "funcCorrNorm_%d",ki);
funcCorrPol->Write(buf,TObject::kOverwrite);
funcCorrConst->Delete();
funcCorrPol->Delete();
//second correction via T1090 (after first)
hSpectrumT1090_EnergyChannelCorr1->GetYaxis()->SetRangeUser(ChannelRangeMin,ChannelRangeMax);
//TF1* FitFuncSlices = new TF1("FitFuncSlices","gaus(0)+pol0(3)",ChannelRangeMin,ChannelRangeMax);
//FitFuncSlices->SetParameters(1000,ChannelPeakPos-10,4,10);
//FitFuncSlices->SetParLimits(1,ChannelRangeMin,ChannelRangeMax);
//FitFuncSlices->SetParLimits(2,0,10);
//FitFuncSlices->SetParLimits(3,0,100);
//gDirectory->ls();
TH1D *hSpectrumT1090_EnergyChannelCorr1_MaxPosManually=new TH1D("hSpectrumT1090_EnergyChannelCorr1_MaxPosManually","",hSpectrumT1090_EnergyChannelCorr1->GetNbinsX(),0,1000);
//cout <<hSpectrumTDeriMax1090_EnergyChannel_MaxPos->GetEntries()<< endl;
for(int binX = hSpectrumT1090_EnergyChannelCorr1->GetXaxis()->FindBin(30);binX <= hSpectrumT1090_EnergyChannelCorr1->GetXaxis()->FindBin(500);binX++)
{
cout << "binx " << binX << endl;
TH1D *hProfileY =hSpectrumT1090_EnergyChannelCorr1->ProjectionY("_py",binX,binX);
//hProfileY->Draw();
//return 0;
double MaxValue=hProfileY->GetBinCenter(hProfileY->GetMaximumBin());
FitFuncSlices = new TF1("FitFuncSlices","gaus(0)+[3]",MaxValue-20,MaxValue+20);
FitFuncGausSlices = new TF1("FitFuncGausSlices","gaus(0)",MaxValue-20,MaxValue+20);
FitFuncGausSlices->SetParameters(hProfileY->GetBinContent(hProfileY->GetMaximumBin()),MaxValue,4);
hProfileY->Fit(FitFuncGausSlices,"RNQ");
示例13: calib
void ll_matrix::matrix_calibration::run_calibration_old( TString basename )
{
vector<double> masses;
vector<double> cal;
vector<double> cal_sigma;
// vector<double> cal_sigma;
vector<TH1F*> min_like;
vector<TH1F*> sigma;
vector<TH1F*> pull;
int mass_index = 0;
for( int idx = 0 ; idx < int( d_sample->samples.size() ) ; idx++ )
{
if( d_sample->samples[idx].mass == 0 )
continue;
double mass = d_sample->samples[idx].mass;
ostringstream input_file_name;
input_file_name << basename << "_ensemble_m" << mass << ".root";
TFile * input_file = TFile::Open( input_file_name.str().c_str() , input_file_name.str().c_str() , "read" );
ostringstream name , fit_name , fit_pull;
name << "graph_name_" << mass;
fit_name << "fit_name_" << mass;
fit_pull << "fit_pull_" << mass;
masses.push_back( mass );
min_like.push_back( new TH1F( name.str().c_str() , name.str().c_str() , 600 , 0 , 600 ) );
sigma.push_back( new TH1F( fit_name.str().c_str() , fit_name.str().c_str() , 200 , -100 , 100 ) );
pull.push_back( new TH1F( fit_pull.str().c_str() , fit_pull.str().c_str() , 100 , -5 , 5 ) );
for( int ens_no = 0 ; ens_no < NUMBER_OF_ENSEMBLES ; ens_no++ )
{
input_file->cd();
ostringstream ens_name;
ens_name << basename << "_ll_mass_" << mass << "_ens_" << ens_no;
TGraphErrors * temp_graph = (TGraphErrors*) input_file->Get( ens_name.str().c_str() );
if( !temp_graph ) continue;
double calib_parms[2] = { 0. , 1. };
// cout << " is this where things break ? " << endl;
pair<double,double> mfit = fit_pol2( temp_graph , calib_parms , 1. );
if( mfit.first > 0. )
{
min_like[mass_index]->Fill( mfit.first );
sigma[mass_index]->Fill( mfit.second );
pull[mass_index]->Fill( ( mfit.first - mass ) / mfit.second );
}
}
mass_index++;
}
ostringstream output_filename;
output_filename << "calibration_" << basename << "_" << NUMBER_PER_ENSEMBLES << "_" << NUMBER_OF_ENSEMBLES << ".root";
cout << "done with loop " << endl;
TFile * outputfile = new TFile( output_filename.str().c_str() , "recreate" );
outputfile->cd();
for( int idx = 0 ; idx < mass_index ; idx++ )
{
min_like[idx]->Write();
sigma[idx]->Write();
pull[idx]->Write();
if( NUMBER_OF_ENSEMBLES > 1 )
{
double temp_sigma = 0.;
double temp_value = 0. , pull_temp_value = 0.;
if( USE_MEAN_RMS )
{
temp_value = min_like[idx]->GetMean();
temp_sigma = min_like[idx]->GetRMS();
pull_temp_value = ( temp_value - masses[idx] ) / min_like[idx]->GetRMS() ;
}
else
{
double max_val = min_like[idx]->GetBinCenter( min_like[idx]->GetMaximumBin() );
min_like[idx]->Fit( "gaus" , "Q" , "" , max_val - 50. , max_val + 50. );
TF1 * func_cal = min_like[idx]->GetFunction( "gaus" );
temp_value = func_cal->GetParameter( 1 );
temp_sigma = func_cal->GetParameter( 2 );
pull_temp_value = ( temp_value - masses[idx] ) / func_cal->GetParameter( 2 );
}
cal.push_back( temp_value );
cal_sigma.push_back( temp_sigma );
}
cout << d_sample->samples[idx].mass << " GeV & "
<< min_like[idx]->GetMean() << " GeV & "
<< min_like[idx]->GetRMS() << " GeV & "
<< pull[idx]->GetMean() << " & "
<< pull[idx]->GetRMS() << " \\ " << endl;
}
//.........这里部分代码省略.........
示例14: Loop
//.........这里部分代码省略.........
TCanvas *accTimesTrgEffPlot = new TCanvas("accTimesTrgEffPlot", "acc x trigger eff", 100, 100, 600, 600);
TPad *accTimesTrgEffPad = (TPad*)accTimesEffPad->Clone("accTimesTrgEffPad");
accTimesTrgEffPad->Draw();
accTimesTrgEffPad->cd();
hAccTimesTrgEff->GetYaxis()->SetTitle("acc x trg eff");
hAccTimesTrgEff->GetYaxis()->SetRangeUser(0., 1.);
hAccTimesTrgEff->SetMarkerStyle(20);
hAccTimesTrgEff->SetMarkerColor(kCyan);
hAccTimesTrgEff->SetLineColor(kCyan);
hAccTimesTrgEff->Draw();
hTrgEff->SetMarkerStyle(21);
hTrgEff->SetMarkerColor(kMagenta);
hTrgEff->SetLineColor(kMagenta);
hTrgEff->Draw("same");
TLegend* trgLegend = (TLegend*)legend->Clone("trgLegend");
trgLegend->Clear();
trgLegend->AddEntry(hTrgEff, "trigger eff in acc");
trgLegend->AddEntry(hAccTimesTrgEff, "acc x trigger eff");
trgLegend->Draw("same");
tex->DrawLatex(0.109, 0.935, "CMS Simulation, 8 TeV");
// safe in various file formats
if (saveSpec) {
if (saveAsPdf) {
accTimesTrgEffPlot->Print(plotDir + accTimesTrgEffPlot->GetName() + ".pdf", "pdf");
accTimesEffPlot->Print(plotDir + accTimesEffPlot->GetName() + ".pdf", "pdf");
accTimesEffPlotEB->Print(plotDir + accTimesEffPlotEB->GetName() + ".pdf", "pdf");
accTimesEffPlotEE->Print(plotDir + accTimesEffPlotEE->GetName() + ".pdf", "pdf");
accTimesEffObjPlot->Print(plotDir + accTimesEffObjPlot->GetName() + ".pdf", "pdf");
accTimesEffNoTrgObjPlot->Print(plotDir + accTimesEffNoTrgObjPlot->GetName() + ".pdf", "pdf");
effAftTrgPlot->Print(plotDir + effAftTrgPlot->GetName() + ".pdf", "pdf");
trgRecoVsRecoPlot->Print(plotDir + trgRecoVsRecoPlot->GetName() + ".pdf", "pdf");
accPlot->Print(plotDir + accPlot->GetName() + ".pdf", "pdf");
}
if (saveAsPng) {
accTimesTrgEffPlot->Print(plotDir + accTimesTrgEffPlot->GetName() + ".png", "png");
accTimesEffPlot->Print(plotDir + accTimesEffPlot->GetName() + ".png", "png");
accTimesEffPlotEB->Print(plotDir + accTimesEffPlotEB->GetName() + ".png", "png");
accTimesEffPlotEE->Print(plotDir + accTimesEffPlotEE->GetName() + ".png", "png");
accTimesEffObjPlot->Print(plotDir + accTimesEffObjPlot->GetName() + ".png", "png");
accTimesEffNoTrgObjPlot->Print(plotDir + accTimesEffNoTrgObjPlot->GetName() + ".png", "png");
effAftTrgPlot->Print(plotDir + effAftTrgPlot->GetName() + ".png", "png");
trgRecoVsRecoPlot->Print(plotDir + trgRecoVsRecoPlot->GetName() + ".png", "png");
accPlot->Print(plotDir + accPlot->GetName() + ".png", "png");
}
if (saveAsRoot) {
accTimesTrgEffPlot->Print(plotDir + accTimesTrgEffPlot->GetName() + ".root", "root");
accTimesEffPlot->Print(plotDir + accTimesEffPlot->GetName() + ".root", "root");
accTimesEffPlotEB->Print(plotDir + accTimesEffPlotEB->GetName() + ".root", "root");
accTimesEffPlotEE->Print(plotDir + accTimesEffPlotEE->GetName() + ".root", "root");
accTimesEffObjPlot->Print(plotDir + accTimesEffObjPlot->GetName() + ".root", "root");
accTimesEffNoTrgObjPlot->Print(plotDir + accTimesEffNoTrgObjPlot->GetName() + ".root", "root");
effAftTrgPlot->Print(plotDir + effAftTrgPlot->GetName() + ".root", "root");
trgRecoVsRecoPlot->Print(plotDir + trgRecoVsRecoPlot->GetName() + ".root", "root");
accPlot->Print(plotDir + accPlot->GetName() + ".root", "root");
}
}
// write histos to file
output->cd();
hGenEvts->Write();
hGenEvtsEleInAcc->Write();
hGenEvtsEleInAccEB->Write();
hGenEvtsEleInAccEE->Write();
hGenEvtsMuInAcc->Write();
hGenEvtsInAcc->Write();
hTrgEvts->Write();
hRecoEvts->Write();
hRecoEvtsEB->Write();
hRecoEvtsEE->Write();
hRecoEleEvts->Write();
hRecoEleEvtsEB->Write();
hRecoEleEvtsEE->Write();
hRecoMuEvts->Write();
hAccEle->Write();
hAccEleEB->Write();
hAccEleEE->Write();
hAccMu->Write();
hAccTimesTrgEff->Write();
hTrgEff->Write();
hAccTimesEff->Write();
hAccTimesEffEB->Write();
hAccTimesEffEE->Write();
hAccTimesEffEle->Write();
hAccTimesEffEleEB->Write();
hAccTimesEffEleEE->Write();
hAccTimesEffMu->Write();
hEffAftTrg->Write();
hEffAftTrgEle->Write();
hEffAftTrgEleEB->Write();
hEffAftTrgEleEE->Write();
hEffAftTrgMu->Write();
fitFunc->Write();
fitFuncEB->Write();
fitFuncEE->Write();
output->Close();
timer.Stop();
timer.Print();
}
示例15: fit
//.........这里部分代码省略.........
TH1D* hempty = new TH1D("", "", 50, minhisto, maxhisto);
TCanvas* c = new TCanvas("c", "", 600, 600);
c->cd();
TF1* f = new TF1(Form("f"),"[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]) + [3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5]) + [9]+[10]*x ");
f->SetParLimits(0, 1e-3, 1e3);
f->SetParLimits(1, 4.9, 5.2);
f->SetParLimits(2, 0.001, 0.1);
f->SetParLimits(3, 1e-3, 1e3);
f->SetParLimits(4, 4.9, 5.2);
f->SetParLimits(5, 0.001, 0.1);
f->SetParLimits(9, 0, 1e2);
f->SetParLimits(10, -10, 10);
f->SetParameter(0,1e2);
f->SetParameter(1,5.11);
f->SetParameter(2,0.05);
f->SetParameter(3,1e2);
f->SetParameter(4,4.98);
f->SetParameter(5,0.05);
f->SetParameter(9,1e3);
f->SetParameter(10,0);
if(fitType==1) {
f->SetParLimits(0, 0, 1e4);
f->SetParLimits(1, 5.2, 5.6);
f->SetParLimits(2, 0.0001, 0.5);
f->SetParameter(0,1e2);
f->SetParameter(1,5.35);
f->SetParameter(2,0.05);
f->SetParLimits(3, 0, 1e4);
f->SetParLimits(4, 5.2, 5.6);
f->SetParLimits(5, 0.0001, 0.5);
f->SetParameter(3,1e2);
f->SetParameter(4,5.35);
f->SetParameter(5,0.05);
}
//h->Fit(Form("f"),"q","",minhisto,maxhisto);
//h->Fit(Form("f"),"q","",minhisto,maxhisto);
//h->Fit(Form("f"),"L q","",minhisto,maxhisto);
//h->Fit(Form("f"),"L m","",minhisto,maxhisto);
h->SetMarkerSize(0.8);
h->SetMarkerStyle(20);
hempty->SetMaximum(h->GetMaximum()*1.4);
hempty->SetXTitle("m_{#mu#muK} (GeV/c^{2})");
hempty->SetYTitle("Entries / (5 MeV/c^{2})");
hempty->GetXaxis()->CenterTitle();
hempty->GetYaxis()->CenterTitle();
hempty->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y");
hempty->GetXaxis()->SetTitleOffset(1.3);
hempty->GetYaxis()->SetTitleOffset(1.3);
hempty->GetXaxis()->SetLabelOffset(0.007);
hempty->GetYaxis()->SetLabelOffset(0.007);
hempty->GetXaxis()->SetTitleSize(0.045);
hempty->GetYaxis()->SetTitleSize(0.045);
hempty->GetXaxis()->SetTitleFont(42);
hempty->GetYaxis()->SetTitleFont(42);
hempty->GetXaxis()->SetLabelFont(42);
hempty->GetYaxis()->SetLabelFont(42);
hempty->GetXaxis()->SetLabelSize(0.04);
hempty->GetYaxis()->SetLabelSize(0.04);
hempty->SetMarkerSize(0.01);
hempty->SetMarkerStyle(20);
hempty->Draw();
h->Draw("same e");
//f->Draw("same");
TLegend* leg = new TLegend(0.45,0.79,0.65,0.89,NULL,"brNDC");
leg->SetBorderSize(0);
leg->SetTextSize(0.04);
leg->SetTextFont(42);
leg->SetFillStyle(0);
if(fitType==1) leg->AddEntry(h,"B^{+} to Jpsi Pi","p");
if(fitType==2) leg->AddEntry(h,"B^{+} to Jpsi and various K","p");
if(fitType==3) leg->AddEntry(h,"B^{0} to Jpsi and various K","p");
TLatex * tlatex;
if(ispp) tlatex=new TLatex(0.48,0.89,"pp MC");
else tlatex=new TLatex(0.48,0.89,"PbPb MC");
tlatex->SetNDC();
tlatex->SetTextColor(1);
tlatex->SetTextFont(42);
tlatex->SetTextSize(0.04);
tlatex->Draw();
//leg->AddEntry(f,"Fit","l");
leg->Draw("same");
outf->cd();
h->Write();
f->Write();
if(ispp) c->SaveAs(Form("plotspp/%s.png", histname.Data()));
else c->SaveAs(Form("plotsPbPb/%s.png", histname.Data()));
}