本文整理汇总了C++中TH1::SetYTitle方法的典型用法代码示例。如果您正苦于以下问题:C++ TH1::SetYTitle方法的具体用法?C++ TH1::SetYTitle怎么用?C++ TH1::SetYTitle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TH1
的用法示例。
在下文中一共展示了TH1::SetYTitle方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ratioPlots
void ratioPlots( TCanvas* c1, TH1* h_r, TH1* h_i,
string xTitle, string yTitle, string savePath,
double fitMin=-100000, double fitMax=100000, bool doubleColFit=0 ){
double xMaximum = h_r->GetXaxis()->GetBinUpEdge(h_r->GetXaxis()->GetLast());
double xMinimum = h_r->GetXaxis()->GetBinLowEdge(h_r->GetXaxis()->GetFirst());
double yMaximum;
double yMinimum;
h_i->Sumw2();
h_r->Sumw2();
TLine* line1 = new TLine(xMinimum,1,xMaximum,1);
line1->SetLineColor(1);
line1->SetLineWidth(2);
line1->SetLineStyle(7);
TF1* fpol1 = new TF1("fpol1", "pol1", fitMin, fitMax);
fpol1->SetLineColor(2);
fpol1->SetLineWidth(3);
fpol1->SetLineStyle(7);
TH1* hRatio = (TH1*)h_r->Clone("clone_record");
hRatio->Divide(h_i);
yMaximum = hRatio->GetMaximum();
yMinimum = hRatio->GetMinimum(0);
hRatio->GetYaxis()->SetRangeUser(yMinimum/2.5,yMaximum+yMaximum/5);
hRatio->SetXTitle(xTitle.c_str());
hRatio->SetYTitle(yTitle.c_str());
hRatio->SetLineColor(9);
hRatio->SetLineWidth(2);
hRatio->SetMarkerStyle(8);
hRatio->Draw("e");
hRatio->Fit("fpol1", "L");
line1->Draw("SAME");
if(doubleColFit){
double p0=fpol1->GetParameter(0);
double p1=fpol1->GetParameter(1);
double endPoint=double(fitMax*p1)+p0;
double p1new=(endPoint-1)/(fitMax-fitMin);
char fun[100], text[100];
sprintf(fun,"x*(%f)+1",p1new);
sprintf(text,"Tangent: %f",p1new);
TF1* fnew = new TF1("fnew", fun, fitMin, fitMax);
fnew->SetLineColor(2);
fnew->SetLineWidth(3);
fnew->Draw("SAME");
TText* Title = new TText( fitMax/12, yMinimum, text);
Title->SetTextColor(2);
Title->SetTextSize(0.035);
Title->Draw("SAME");
}
c1->SaveAs(savePath.c_str());
c1->cd();
}
示例2: One
//____________________________________________________________________
TH1* One(TDirectory* newDir, TDirectory* oldDir, Double_t c1, Double_t c2)
{
TString name;
name.Form("cent%03dd%02d_%03dd%02d",
Int_t(c1), Int_t(c1*100)%100,
Int_t(c2), Int_t(c2*100)%100);
TDirectory* newSubDir = GetD(newDir, name);
TDirectory* oldSubDir = GetD(oldDir, name);
if (!newSubDir || !oldSubDir) return 0;
Int_t newDim = 0;
if (TString(newDir->GetName()).Contains("etaipz")) newDim = 3;
else if (TString(newDir->GetName()).Contains("eta")) newDim = 2;
else if (TString(newDir->GetName()).Contains("const")) newDim = 1;
Int_t oldDim = 0;
if (TString(oldDir->GetName()).Contains("etaipz")) oldDim = 3;
else if (TString(oldDir->GetName()).Contains("eta")) oldDim = 2;
else if (TString(oldDir->GetName()).Contains("const")) oldDim = 1;
TDirectory* newSubSubDir = GetD(newSubDir, Form("results%dd",newDim));
TDirectory* oldSubSubDir = GetD(oldSubDir, Form("results%dd",oldDim));
if (!newSubSubDir || !oldSubSubDir) return 0;
TH1* newRes = GetH1(newSubSubDir, "result");
TH1* oldRes = GetH1(oldSubSubDir, "result");
if (!newRes || !oldRes) return 0;
TH1* ratio = static_cast<TH1*>(newRes->Clone(name));
ratio->SetDirectory(0);
ratio->SetTitle(Form("%5.1f - %5.1f%%", c1, c2));
ratio->SetYTitle("New / Old");
ratio->Divide(oldRes);
fMin = TMath::Min(fMin, ratio->GetMinimum());
fMax = TMath::Max(fMax, ratio->GetMaximum());
Printf("Calculated %s/%s", newDir->GetName(), oldDir->GetName());
if (!fLegend) return ratio;
TLegendEntry* e =
fLegend->AddEntry("", Form("%3.0f - %3.0f%%", c1, c2), "f");
e->SetFillStyle(1001);
e->SetFillColor(ratio->GetMarkerColor());
return ratio;
}
示例3: main
//.........这里部分代码省略.........
s = 0;
for(int i = 1; i <= histoZMuMuNoIso->GetNbinsX(); ++i)
s += histoZMuMuNoIso->GetBinContent(i);
histoZMuMuNoIso->SetEntries(s);
s = 0;
for(int i = 1; i <= histoZMuMu->GetNbinsX(); ++i)
s += histoZMuMu->GetBinContent(i);
histoZMuMu->SetEntries(s);
s = 0;
for(int i = 1; i <= histoZMuMu1HLT->GetNbinsX(); ++i)
s += histoZMuMu1HLT->GetBinContent(i);
histoZMuMu1HLT->SetEntries(s);
s = 0;
for(int i = 1; i <= histoZMuMu2HLT->GetNbinsX(); ++i)
s += histoZMuMu2HLT->GetBinContent(i);
histoZMuMu2HLT->SetEntries(s);
s = 0;
for(int i = 1; i <= histoZMuTk->GetNbinsX(); ++i)
s += histoZMuTk->GetBinContent(i);
histoZMuTk->SetEntries(s);
s = 0;
for(int i = 1; i <= histoZMuSa->GetNbinsX(); ++i)
s += histoZMuSa->GetBinContent(i);
histoZMuSa->SetEntries(s);
string ZMuMu1HLTPlot = "ZMuMu1HLTFit_" + plot_string;
root::plot<Expr>(ZMuMu1HLTPlot.c_str(), *histoZMuMu1HLT, zMuMu1HLT, fMin, fMax,
effTk, effSa, effIso, effHLT, yieldZMuMu,
kRed, 2, kDashed, 100,
"Z -> #mu #mu mass", "#mu #mu invariant mass (GeV/c^{2})",
"Events");
string ZMuMu2HLTPlot = "ZMuMu2HLTFit_" + plot_string;
root::plot<Expr>(ZMuMu2HLTPlot.c_str(), *histoZMuMu2HLT, zMuMu2HLT, fMin, fMax,
effTk, effSa, effIso, effHLT, yieldZMuMu,
kRed, 2, kDashed, 100,
"Z -> #mu #mu mass", "#mu #mu invariant mass (GeV/c^{2})",
"Events");
string ZMuMuNoIsoPlot = "ZMuMuNoIsoFit_" + plot_string;
root::plot<Expr>(ZMuMuNoIsoPlot.c_str(), *histoZMuMuNoIso, zMuMuNoIso, fMin, fMax,
effTk, effSa, effIso, effHLT, yieldZMuMu,
kRed, 2, kDashed, 100,
"Z -> #mu #mu Not Iso mass", "#mu #mu invariant mass (GeV/c^{2})",
"Events");
string ZMuTkPlot = "ZMuTkFit_X_" + plot_string;
root::plot<Expr>(ZMuTkPlot.c_str(), *histoZMuTk, zMuTk, fMin, fMax,
effTk, effSa, effIso, effHLT, yieldZMuMu,
yieldBkgZMuTk, lambda, a0, a1, a2,
kRed, 2, kDashed, 100,
"Z -> #mu + (unmatched) track mass", "#mu #mu invariant mass (GeV/c^{2})",
"Events");
ZMuTkPlot = "ZMuTkFit_" + plot_string;
TF1 funZMuTk = root::tf1_t<sig_tag, Expr>("ZMuTkFunction", zMuTk, fMin, fMax,
effTk, effSa, effIso, effHLT, yieldZMuMu,
yieldBkgZMuTk, lambda, a0, a1, a2);
funZMuTk.SetLineColor(kRed);
funZMuTk.SetLineWidth(2);
funZMuTk.SetLineStyle(kDashed);
funZMuTk.SetNpx(10000);
TF1 funZMuTkBkg = root::tf1_t<bkg_tag, Expr>("ZMuTkBack", zMuTkBkgScaled, fMin, fMax,
yieldBkgZMuTk, lambda, a0, a1, a2);
funZMuTkBkg.SetLineColor(kGreen);
funZMuTkBkg.SetLineWidth(2);
funZMuTkBkg.SetLineStyle(kDashed);
funZMuTkBkg.SetNpx(10000);
histoZMuTk->SetTitle("Z -> #mu + (unmatched) track mass");
histoZMuTk->SetXTitle("#mu + (unmatched) track invariant mass (GeV/c^{2})");
histoZMuTk->SetYTitle("Events");
TCanvas *canvas = new TCanvas("canvas");
histoZMuTk->Draw("e");
funZMuTkBkg.Draw("same");
funZMuTk.Draw("same");
canvas->SaveAs(ZMuTkPlot.c_str());
canvas->SetLogy();
string logZMuTkPlot = "log_" + ZMuTkPlot;
canvas->SaveAs(logZMuTkPlot.c_str());
string ZMuSaPlot = "ZMuSaFit_" + plot_string;
root::plot<Expr>(ZMuSaPlot.c_str(), *histoZMuSa, zMuSa, fMin, fMax,
effSa, effTk, effIso,
yieldZMuMu, yieldBkgZMuSa,
kRed, 2, kDashed, 10000,
"Z -> #mu + (unmatched) standalone mass",
"#mu + (unmatched) standalone invariant mass (GeV/c^{2})",
"Events");
}
}
}
catch(std::exception& e) {
cerr << "error: " << e.what() << "\n";
return 1;
}
catch(...) {
cerr << "Exception of unknown type!\n";
}
return 0;
}
示例4: DrawKs
TCanvas* DrawKs(const char* filename)
{
TFile* file = TFile::Open(filename, "READ");
if (!file) {
Warning("DrawKs", "File %s couldn't be opened", filename);
return 0;
}
TH1* cent = static_cast<TH1*>(file->Get("cent"));
if (!cent) {
Warning("DrawKs", "Failed to find cent in %s", file->GetName());
return 0;
}
TString t(filename);
t.ReplaceAll("results/", "");
t.ReplaceAll("combine_","");
t.ReplaceAll("_0x3.root", "");
TString nm(filename);
nm.ReplaceAll(".root", "");
nm.ReplaceAll("results/", "plots/");
nm.ReplaceAll("combine", "ks");
if (t.Contains("none"))
t.ReplaceAll("none", "No weights");
else
t.Append(" weights");
Int_t cW = 1200;
Int_t cH = 800;
TCanvas* c = new TCanvas(nm,t,cW, cH);
c->SetTopMargin(0.07);
c->SetRightMargin(0.20);
c->SetTicks();
TLegend* l = new TLegend(1-c->GetRightMargin(),
c->GetBottomMargin(),
.99,
1-c->GetTopMargin());
l->SetFillStyle(0);
l->SetBorderSize(0);
THStack* s = new THStack("ks", "");
Int_t nCent = cent->GetXaxis()->GetNbins();
for (Int_t i = 1; i <= nCent; i++) {
Double_t c1 = cent->GetXaxis()->GetBinLowEdge(i);
Double_t c2 = cent->GetXaxis()->GetBinUpEdge(i);
TH1* h = GetCentK(file, c1, c2, nCent-i+1-2, l);
if (!h) continue;
s->Add(h);
}
s->Draw("nostack");
TH1* f = s->GetHistogram();
if (f) {
f->SetXTitle("#eta");
f->SetYTitle("#it{k}(#eta)");
}
TLatex* tit = new TLatex(0.55, 0.99, t);
tit->SetTextFont(42);
tit->SetTextAlign(23);
tit->SetTextSize(0.03);
tit->SetNDC();
tit->Draw();
l->SetBorderSize(0);
l->Draw();
c->Modified();
c->Update();
c->cd();
return c;
}
示例5: ProcessBin
/**
* Process a single eta bin
*
* @param measured Input collection of measured data
* @param corrections Input collection of correction data
* @param method Unfolding method to use
* @param regParam Regularisation parameter
* @param out Output directory.
*
* @return Stack of histograms or null
*/
THStack* ProcessBin(TCollection* measured,
TCollection* corrections,
UInt_t method,
Double_t regParam,
TDirectory* out)
{
Printf(" Processing %s ...", measured->GetName());
// Try to get the data
TH1* inRaw = GetH1(measured, "rawDist");
TH1* inTruth = GetH1(corrections, "truth");
TH1* inTruthA = GetH1(corrections, "truthAccepted");
TH1* inTrgVtx = GetH1(corrections, "triggerVertex");
TH2* inResp = GetH2(corrections, "response");
if (!inRaw || !inTruth || !inTruthA || !inTrgVtx || !inResp)
return 0;
// Make output directory
TDirectory* dir = out->mkdir(measured->GetName());
dir->cd();
// Copy the input to the output
TH1* outRaw = static_cast<TH1*>(inRaw ->Clone("measured"));
TH1* outTruth = static_cast<TH1*>(inTruth ->Clone("truth"));
TH1* outTruthA = static_cast<TH1*>(inTruthA ->Clone("truthAccepted"));
TH1* outTrgVtx = static_cast<TH1*>(inTrgVtx ->Clone("triggerVertex"));
TH2* outResp = static_cast<TH2*>(inResp ->Clone("response"));
// Make our response matrix
RooUnfoldResponse matrix(0, 0, inResp);
// Store regularization parameter
Double_t r = regParam;
RooUnfold::Algorithm algo = (RooUnfold::Algorithm)method;
RooUnfold* unfolder = RooUnfold::New(algo, &matrix, inRaw, r);
unfolder->SetVerbose(0);
// Do the unfolding and get the result
TH1* res = unfolder->Hreco();
res->SetDirectory(0);
// Make a copy to store on the output
TH1* outUnfold = static_cast<TH1*>(res->Clone("unfolded"));
TString tit(outUnfold->GetTitle());
tit.ReplaceAll("Unfold Reponse matrix", "Unfolded P(#it{N}_{ch})");
outUnfold->SetTitle(tit);
// Clone the unfolded results and divide by the trigger/vertex
// bias correction
TH1* outCorr = static_cast<TH1*>(outUnfold->Clone("corrected"));
outCorr->Divide(inTrgVtx);
tit.ReplaceAll("Unfolded", "Corrected");
outCorr->SetTitle(tit);
// Now normalize the output to integral=1
TH1* hists[] = { outRaw, outUnfold, outCorr, 0 };
TH1** phist = hists;
while (*phist) {
TH1* h = *phist;
if (h) {
Double_t intg = h->Integral(1, h->GetXaxis()->GetXmax());
h->Scale(1. / intg, "width");
}
phist++;
}
// And make ratios
TH1* ratioTrue = static_cast<TH1*>(outCorr->Clone("ratioCorrTruth"));
tit = ratioTrue->GetTitle();
tit.ReplaceAll("Corrected", "Corrected/MC 'truth'");
ratioTrue->SetTitle(tit);
ratioTrue->Divide(outTruth);
ratioTrue->SetYTitle("P_{corrected}(#it{N}_{ch})/P_{truth}(#it{N}_{ch})");
TH1* ratioAcc = static_cast<TH1*>(outUnfold->Clone("ratioUnfAcc"));
tit = ratioAcc->GetTitle();
tit.ReplaceAll("Unfolded", "Unfolded/MC selected");
ratioAcc->SetTitle(tit);
ratioAcc->Divide(outTruthA);
ratioAcc->SetYTitle("P_{unfolded}(#it{N}_{ch})/P_{MC}(#it{N}_{ch})");
// Make a stack
tit = measured->GetName();
tit.ReplaceAll("m", "-");
tit.ReplaceAll("p", "+");
tit.ReplaceAll("d", ".");
tit.ReplaceAll("_", "<#it{#eta}<");
THStack* stack = new THStack("all", tit);
stack->Add(outTruth, "E2");
//.........这里部分代码省略.........
示例6: HwwNoteFigs
void HwwNoteFigs(TString filename = "../histo_tmva_new-ntuples-1_160_0.root",
int mass = 170, int ReBin = 4, int ysel = 0)
{
TFile* infile = new TFile(filename.Data(),"READ");
setTDRStyle(0);
//BDTD dists
TCanvas* c1 = new TCanvas("c1","c1",0,-200,500,500);
TH1F* histoBg = histo4->Clone();
histoBg->Add(histo3);
histoBg->Add(histo2);
histoBg->Add(histo1);
TH1F* histo_4 = histo4->Clone();
histo3->Add(histo_4);
TH1F* histo_3 = histo3->Clone();
histo2->Add(histo_3);
TH1F* histo_2 = histo2->Clone();
histo1->Add(histo_2);
histo1->Rebin(ReBin);
histo1->SetFillColor(kBlue);
histo1->SetFillStyle(1001);
histo1->SetLineStyle(0);
histo1->SetLineWidth(0);
histo2->Rebin(ReBin);
histo2->SetFillColor(kMagenta);
histo2->SetFillStyle(1001);
histo2->SetLineStyle(0);
histo2->SetLineWidth(0);
histo3->Rebin(ReBin);
histo3->SetFillColor(kGreen);
histo3->SetFillStyle(1001);
histo3->SetLineStyle(0);
histo3->SetLineWidth(0);
histo4->Rebin(ReBin);
histo4->SetFillColor(kCyan);
histo4->SetFillStyle(1001);
histo4->SetLineStyle(0);
histo4->SetLineWidth(0);
char YTitle[300];
sprintf(YTitle,"events / bin");
char XTitle[300];
sprintf(XTitle,"BDT Output");
histo0->SetYTitle(YTitle);
histo1->SetYTitle(YTitle);
histo2->SetYTitle(YTitle);
histo3->SetYTitle(YTitle);
histo4->SetYTitle(YTitle);
histo0->SetXTitle(XTitle);
histo1->SetXTitle(XTitle);
histo2->SetXTitle(XTitle);
histo3->SetXTitle(XTitle);
histo4->SetXTitle(XTitle);
histo1->SetTitleSize(0.05, "X");
histo1->GetXaxis()->SetTitleFont(62);
histo1->GetXaxis()->SetLabelFont(61);
histo1->GetYaxis()->SetLabelFont(61);
histo1->GetYaxis()->SetTitleOffset(1.3);
histo1->SetLabelSize(0.04, "Y");
histo1->SetLabelSize(0.04, "X");
int min = histoBg->FindBin(-1.5);
int max = histoBg->FindBin(1.5);
histoBg->GetXaxis()->SetRange(min,max);
histoBg->SetMarkerStyle(20);
histoBg->SetMarkerSize(1.0);
histoBg->GetYaxis()->SetTitleOffset(1.40);
histo0->SetMarkerStyle(21);
histo0->SetMarkerSize(1.0);
histoBg->Rebin(ReBin);
histo0->Rebin(ReBin);
histoBg->SetLineColor(4);
histo0->SetLineColor(1);
scaleHist(histoBg);
scaleHist(histo0);
cout << "bg events: " << histoBg->GetSumOfWeights() << endl;
cout << "si events: " << histo0->GetSumOfWeights() << endl;
histoBg->SetYTitle("Events");
histo1->SetMinimum(0.01);
if(ysel == 0) {
histo1->Draw("hist");
}
else {
histo0->Draw("E");
histo1->Draw("hist,same");
}
//.........这里部分代码省略.........
示例7: plot
//.........这里部分代码省略.........
TH1* ewkDY = (TH1*)f->Get("EWK_DYx");
TH1* ewkVV = (TH1*)f->Get("EWK_VVx");
ewktau->Add(ewkDY);
ewktau->Add(ewkVV);
//TH1* qcd = (TH1*)f->Get("QCDInv");
TH1* qcd = (TH1*)f->Get("QCD");
ci = TColor::GetColor("#ffcc33");
qcd->SetFillColor(ci);
qcd->SetLineWidth(0);
TH1* fakett = (TH1*)f->Get("fake_tt");
ci = TColor::GetColor("#669900");
fakett->SetFillColor(ci);
fakett->SetLineWidth(0);
TH1* fakeW = (TH1*)f->Get("fake_W");
ci = TColor::GetColor("#cc3300");
fakeW->SetFillColor(ci);
fakeW->SetLineWidth(0);
TH1* faket = (TH1*)f->Get("fake_t");
TH1F *hFrame = new TH1F("hFrame","",20,0,400);
hFrame->SetMinimum(ymin);
if (log)
hFrame->SetMaximum(ymax*1.5);
else
hFrame->SetMaximum(ymax);
hFrame->SetDirectory(0);
hFrame->SetStats(0);
hFrame->SetLineStyle(0);
hFrame->SetMarkerStyle(20);
hFrame->SetXTitle("Transverse mass (#tau jet, E_{T}^{miss}), (GeV/c^{2})");
if (paperStatus)
hFrame->SetXTitle("Transverse mass (#tau_{h}, E_{T}^{miss}), (GeV/c^{2})");
hFrame->SetYTitle("Events / 20 GeV/c^{2}");
hFrame->GetXaxis()->SetTitleSize(0);
hFrame->GetXaxis()->SetLabelSize(0);
hFrame->GetYaxis()->SetTitleFont(43);
hFrame->GetYaxis()->SetTitleSize(27);
hFrame->GetYaxis()->SetTitleOffset(1.3);
// signal
hh->Scale(br*br);
hw->Scale(2*br*(1.0-br));
TH1* signal = (TH1*)hh->Clone();
signal->Add(hw);
ci = TColor::GetColor("#ff3399");
signal->SetLineColor(ci);
signal->SetLineStyle(2);
signal->SetLineWidth(2);
// Fakes
TH1* fakes = (TH1*)(fakett->Clone());
fakes->Add(fakeW);
fakes->Add(faket);
// stacked backgrounds
THStack *exp = new THStack();
exp->SetName("exp");
exp->SetTitle("exp");
exp->Add(fakes);
exp->Add(ewktau);
exp->Add(qcd);
exp->Add(signal);
示例8: makeResidualsControlPlot
void Template::makeResidualsControlPlot(const string& tag, unsigned int rebin)
/*****************************************************************/
{
if(numberOfDimensions()>0 && m_template->GetNbinsX()%rebin!=0) return;
if(numberOfDimensions()>1 && m_template->GetNbinsY()%rebin!=0) return;
if(numberOfDimensions()>2 && m_template->GetNbinsZ()%rebin!=0) return;
stringstream cpName, cpRawName, resMapName, resDistName, relErrDistName;
cpName << m_name << "_cp";
cpRawName << m_name << "_rawcp";
resMapName << m_name << "_resmap_" << tag << "_rebin" << rebin;
resDistName << m_name << "_resdist_" << tag << "_rebin" << rebin;
relErrDistName << m_name << "_relerrdist_" << tag << "_rebin" << rebin;
TH1* cpTmp = NULL;
TH1* cpRawTmp = NULL;
if(rebin==1)
{
cpTmp = dynamic_cast<TH1*>(m_template->Clone(cpName.str().c_str()));
cpRawTmp = dynamic_cast<TH1*>(m_rawTemplate->Clone(cpRawName.str().c_str()));
}
else
{
if(numberOfDimensions()==2)
{
cpTmp = dynamic_cast<TH2F*>(m_template)->Rebin2D(rebin, rebin, cpName.str().c_str());
cpRawTmp = dynamic_cast<TH2F*>(m_rawTemplate)->Rebin2D(rebin, rebin, cpName.str().c_str());
}
else if(numberOfDimensions()==3)
{
cpTmp = dynamic_cast<TH3F*>(m_template)->Rebin3D(rebin, rebin, rebin, cpName.str().c_str());
cpRawTmp = dynamic_cast<TH3F*>(m_rawTemplate)->Rebin3D(rebin, rebin, rebin, cpName.str().c_str());
}
}
TH1* resMap = dynamic_cast<TH1*>(cpTmp->Clone(resMapName.str().c_str()));
TH1D* resDist = new TH1D(resDistName.str().c_str(), resDistName.str().c_str(), 30, -3, 3);
resDist->StatOverflows();
TH1D* relErrDist = new TH1D(relErrDistName.str().c_str(), relErrDistName.str().c_str(), 200, -1, 1);
relErrDist->StatOverflows();
unsigned int nbins1 = cpTmp->GetNbinsX();
unsigned int nbins2 = cpTmp->GetNbinsY();
unsigned int nbins3 = cpTmp->GetNbinsZ();
for(unsigned int b1=1;b1<=nbins1;b1++)
{
for(unsigned int b2=1;b2<=nbins2;b2++)
{
for(unsigned int b3=1;b3<=nbins3;b3++)
{
double tmpValue = cpTmp->GetBinContent(b1,b2,b3);
double tmpRawValue = cpRawTmp->GetBinContent(b1,b2,b3);
double tmpRawError = cpRawTmp->GetBinError(b1,b2,b3);
if(tmpValue>0. && tmpRawValue>0. && tmpRawError>0.)
{
double res = (tmpRawValue-tmpValue)/tmpRawError;
double relErr = (tmpRawValue-tmpValue)/tmpRawValue;
if(numberOfDimensions()==2)
{
resMap->SetBinContent(b1,b2,b3, res);
resMap->SetBinError(b1,b2,b3, 0.);
}
resDist->Fill(res);
relErrDist->Fill(relErr);
}
}
}
}
stringstream plotMapName, plotDistName, plotErrDistName;
plotMapName << "control_" << getName() << "_resMap" << "_" << tag << "_rebin" << rebin;
plotDistName << "control_" << getName() << "_resDist" << "_" << tag << "_rebin" << rebin;
plotErrDistName << "control_" << getName() << "_relErrDist" << "_" << tag << "_rebin" << rebin;
if(numberOfDimensions()==2)
{
TCanvas* c = new TCanvas(plotMapName.str().c_str(),plotMapName.str().c_str(), 700,700);
resMap->SetContour(99);
resMap->SetAxisRange(-3., 3., "z");
resMap->Draw("color z");
resMap->SetXTitle(getVariable(0).c_str());
resMap->SetYTitle(getVariable(1).c_str());
addControlPlot(c);
}
TCanvas* c2 = new TCanvas(plotDistName.str().c_str(),plotDistName.str().c_str(), 700,700);
resDist->SetLineColor(kBlack);
resDist->SetLineWidth(2);
resDist->SetMarkerColor(kBlack);
resDist->SetMarkerStyle(20);
resDist->SetXTitle("(raw-template)/error_{raw}");
resDist->Draw();
addControlPlot(c2);
TCanvas* c3 = new TCanvas(plotErrDistName.str().c_str(),plotErrDistName.str().c_str(), 700,700);
relErrDist->SetLineColor(kBlack);
relErrDist->SetLineWidth(2);
relErrDist->SetMarkerColor(kBlack);
relErrDist->SetMarkerStyle(20);
relErrDist->SetXTitle("(raw-template)/raw");
relErrDist->Draw();
addControlPlot(c3);
if(cpTmp) delete cpTmp;
if(cpRawTmp) delete cpRawTmp;
}
示例9: DrawTwoInPad
void DrawTwoInPad(TVirtualPad* p,
Int_t sub,
TH1* h1,
TH1* h2,
Bool_t ratio,
Bool_t logy=false,
Bool_t legend=false)
{
TVirtualPad* pp = p->cd(sub);
pp->SetRightMargin(0.02);
pp->SetLeftMargin(0.10);
TVirtualPad* ppp = pp;
if (ratio) {
pp->Divide(1,2,0,0);
ppp = pp->cd(1);
ppp->SetRightMargin(0.02);
}
if (logy) ppp->SetLogy();
TH1* hs[] = { h1, h2, 0 };
if (h1->GetMaximum() < h2->GetMaximum()) {
hs[0] = h2;
hs[1] = h1;
}
TH1** ph = hs;
Double_t size = (ratio ? 0.1 : 0.05);
Double_t off = (ratio ? 0.6 : 0.5);
h1->SetFillStyle(3004);
h2->SetFillStyle(3005);
while (*ph) {
TString opt("hist");
if (ph != hs) opt.Append(" same");
TH1* copy = (*ph)->DrawCopy(opt);
copy->GetXaxis()->SetLabelSize(2*size);
copy->GetYaxis()->SetLabelSize(size);
copy->GetYaxis()->SetTitleSize(size);
copy->GetYaxis()->SetTitleOffset(off);
copy->SetYTitle(copy->GetTitle());
copy->SetTitle("");
copy->SetDirectory(0);
ph++;
}
TString s1 = h1->GetYaxis()->GetTitle();
TString s2 = h2->GetYaxis()->GetTitle();
if (legend) {
TLegend* l = new TLegend(0.6, 0.1, 0.9, 0.9);
l->SetBorderSize(0);
TLegendEntry* e = l->AddEntry("dummy", s1, "lf");
l->SetFillColor(kWhite);
e->SetFillColor(kBlack);
e->SetFillStyle(h1->GetFillStyle());
e = l->AddEntry("dummy", s2, "lf");
e->SetFillColor(kBlack);
e->SetFillStyle(h2->GetFillStyle());
l->Draw();
}
if (!ratio) return;
ppp = pp->cd(2);
ppp->SetRightMargin(0.02);
TH1* r = static_cast<TH1*>(h1->Clone(Form("ratio%s", h1->GetName())));
r->SetDirectory(0);
r->SetTitle("");
r->GetXaxis()->SetLabelSize(size);
r->GetYaxis()->SetLabelSize(size);
r->GetYaxis()->SetTitleSize(0.9*size);
r->GetYaxis()->SetTitleOffset(0.9*off);
r->SetMarkerStyle(20);
r->SetMarkerColor(h1->GetFillColor()+1);
r->SetFillStyle(3007);
r->SetYTitle(Form("#frac{%s}{%s}", s1.Data(), s2.Data()));
// r->Add(h2, -1);
// r->Divide(h1);
if (!r->IsA()->InheritsFrom(TProfile::Class())) {
r->GetSumw2()->Set(0); // r->Sumw2(false);
h2->GetSumw2()->Set(0); // h2->Sumw2(false);
}
r->Divide(h2);
Printf("%s", r->GetName());
for (UShort_t bin = 1; bin <= r->GetNbinsX(); bin++) {
Printf(" bin # %2d: Diff=%g+/-%g", bin, r->GetBinContent(bin),
r->GetBinError(bin));
r->SetBinError(bin, 0);
}
r->GetSumw2()->Set(0); //r->Sumw2(false);
r->SetMarkerSize(4);
r->SetMaximum(r->GetMaximum()*1.2);
r->SetMinimum(r->GetMinimum()*0.8);
r->Draw("hist text30");
p->Modified();
p->Update();
p->cd();
}