Hi.
I solved the problem so far.
One thing I’m curious about is where should I use TLegend to get color bar information?
Before I drew bkg+signal histograms, when I drew bkg and signal respectively, I showed color bar information like the picture below.
However, when I drew bkg+signal histogram, color bar information was not generated even if I put TLegend anywhere.
Like the picture below.
I will attach my code together for your reference.
If you know the solution, please let me know.
void tt_d() {
TChain chain1("B_tree");
std::string file_1 = "/home/belle2/hyuna/Signal.root";
chain1.Add(file_1.c_str());
TChain chain2("B_tree");
std::string file_2 = "/home/belle2/hyuna/test_job6/charged.root";
chain2.Add(file_2.c_str());
TChain chain3("B_tree");
std::string file_3 = "/home/belle2/hyuna/test_job7/mixed.root";
chain3.Add(file_3.c_str());
TChain chain4("B_tree");
std::string file_4 = "/home/belle2/hyuna/test_job8/ccbar.root";
chain4.Add(file_4.c_str());
TChain chain5("B_tree");
std::string file_5 = "/home/belle2/hyuna/test_job9/uubar.root";
chain5.Add(file_5.c_str());
TChain chain6("B_tree");
std::string file_6 = "/home/belle2/hyuna/test_job10/ddbar.root";
chain6.Add(file_6.c_str());
TChain chain7("B_tree");
std::string file_7 = "/home/belle2/hyuna/test_job11/ssbar.root";
chain7.Add(file_7.c_str());
TCanvas *c1 = new TCanvas();
TPad *pad1 = new TPad("pad1","",0,0,1,1);
TPad *pad2 = new TPad("pad2","",0,0,1,1);
pad2->SetFillStyle(4000);
pad2->SetFrameFillStyle(0);
gStyle->SetOptStat(0);
TH1F *h1 = new TH1F("signal","",200,-1.0,1.0);
TH1F *h2 = new TH1F("charged","charged",200,-1.0,1.0);
TH1F* h3 = new TH1F("mixed","mixed",200,-1.0,1.0);
TH1F* h4 = new TH1F("ccbar","ccbar",200,-1.0,1.0);
TH1F* h5 = new TH1F("uubar","uubar",200,-1.0,1.0);
TH1F* h6 = new TH1F("ddbar","ddbar",200,-1.0,1.0);
TH1F* h7 = new TH1F("ssbar","ssbar",200,-1.0,1.0);
THStack *hs1 = new THStack("BtoK+gg"," BtoK+gg");
// chain1.Draw("Mbc >> signal", "");
chain2.Draw("deltaE >> charged", "(387.1*10^6/((1.8*10^5)*(1+(0.5346/0.5654))))");
chain3.Draw("deltaE >> mixed", "(387.1*10^6/((1.8*10^5)*(1+(0.5346/0.5654))))*(0.5346/0.5654)");
chain4.Draw("deltaE >> ccbar", "(387.1*10^6/((1.8*10^5)*(1+(0.5346/0.5654))))*(1.329/0.5654)");
chain5.Draw("deltaE >> uubar", "(387.1*10^6/((1.8*10^5)*(1+(0.5346/0.5654))))*(1.605/0.5654)");
chain6.Draw("deltaE >> ddbar", "(387.1*10^6/((1.8*10^5)*(1+(0.5346/0.5654))))*(0.401/0.5654)");
chain7.Draw("deltaE >> ssbar", "(387.1*10^6/((1.8*10^5)*(1+(0.5346/0.5654))))*(0.383/0.5654)");
TLegend* legend = gPad->BuildLegend(0.1,0.7,0.3,0.9);
hs1->Add(h2); h2->SetLineStyle(1); h2->SetLineWidth(2); h2->SetLineColor(41); h2->SetFillColor(41);
hs1->Add(h3); h3->SetLineStyle(1); h3->SetLineWidth(2); h3->SetLineColor(46); h3->SetFillColor(46);
hs1->Add(h4); h4->SetLineStyle(1); h4->SetLineWidth(2); h4->SetLineColor(29); h4->SetFillColor(29);
hs1->Add(h5); h5->SetLineStyle(1); h5->SetLineWidth(2); h5->SetLineColor(24); h5->SetFillColor(24);
hs1->Add(h6); h6->SetLineStyle(1); h6->SetLineWidth(2); h6->SetLineColor(48); h6->SetFillColor(48);
hs1->Add(h7); h7->SetLineStyle(1); h7->SetLineWidth(2); h7->SetLineColor(16); h7->SetFillColor(16);
// TLegend* legend = gPad->BuildLegend(0.1,0.7,0.3,0.9);
pad1->Draw();
pad1->cd();
hs1->Draw("h");
pad2->Draw();
pad2->cd();
chain1.Draw("deltaE >> signal", "");
h1->SetLineColor(kRed);
h1->Draw("Y+");
c1 -> SaveAs("bkg_signal_deltaE.png");
}