本文整理汇总了C++中THStack::SetTitle方法的典型用法代码示例。如果您正苦于以下问题:C++ THStack::SetTitle方法的具体用法?C++ THStack::SetTitle怎么用?C++ THStack::SetTitle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类THStack
的用法示例。
在下文中一共展示了THStack::SetTitle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: THStack
THStack * FromTH1FMakeTHStack(vector<TH1F*> * histo, TString stack_name, vector<TString> * h_description, bool order_size, bool nostack, TString x_axis, TString y_axis, TH1F * data){
if((int) histo->size() != (int) h_description->size()){ Error("Histogram numbers and legend items do not match");}
THStack * stack = new THStack("stack", stack_name);
stack->SetTitle("");
TLegend * legend = new TLegend(0.7,0.5,0.9,0.9);
legend->SetFillColor(0);
Int_t h_array_size = (int) histo->size();
Int_t reorder[h_array_size];
if(order_size){
Float_t integral[h_array_size];
for(int itr = 0; itr < h_array_size; itr++){
integral[itr] = (*histo)[itr]->Integral();
}
for(int itr1 = 0; itr1 < h_array_size; itr1++){
for(int itr2 = 0; itr2 < h_array_size; itr2++){
if(itr1 == itr2) continue;
if(integral[itr1] < integral[itr2]){
reorder[itr1] += 1;
}
}
}
}
for(int itr = 0; itr < h_array_size; itr++){
if( nostack ){ stack->Add((*histo)[reorder[itr]], "nostack"); }
if(!nostack ){ stack->Add((*histo)[reorder[itr]]); }
legend->AddEntry((*histo)[itr], (*h_description)[itr], "f");
}
if(data != NULL){
stack->Add(data, "nostack");
legend->AddEntry(data, "Data", "p");
}
return stack;
}
示例2: plotSS
//.........这里部分代码省略.........
for (int iSubDet=1; iSubDet<=6; ++iSubDet) {
// TEC requires special care since rings 1-4 and 5-7 are plotted separately
bool isTEC = (iSubDet==6);
// if subdet is specified, skip other subdets
if (plotSubDetN!=0 && iSubDet!=plotSubDetN)
continue;
// Skips plotting too high layers
if (plotLayerN > numberOfLayers[iSubDet-1]) {
continue;
}
int minlayer = plotLayers ? 1 : plotLayerN;
int maxlayer = plotLayers ? numberOfLayers[iSubDet-1] : plotLayerN;
for (int layer = minlayer; layer <= maxlayer; layer++) {
// two plots for TEC, skip first
for (int iTEC = 0; iTEC<2; iTEC++) {
if (!isTEC && iTEC==0) continue;
char selection[1000];
if (!isTEC){
if (layer==0)
sprintf(selection,"subDetId==%d",iSubDet);
else
sprintf(selection,"subDetId==%d && layer == %d",iSubDet,layer);
}
else{ // TEC
if (iTEC==0) // rings
sprintf(selection,"subDetId==%d && ring <= 4",iSubDet);
else
sprintf(selection,"subDetId==%d && ring > 4",iSubDet);
}
// Title for plot and name for the file
TString subDetName;
switch (iSubDet) {
case 1: subDetName = "BPIX"; break;
case 2: subDetName = "FPIX"; break;
case 3: subDetName = "TIB"; break;
case 4: subDetName = "TID"; break;
case 5: subDetName = "TOB"; break;
case 6: subDetName = "TEC"; break;
}
TString myTitle = "Surface Shape, ";
myTitle += subDetName;
if (layer!=0) {
myTitle += TString(", layer ");
myTitle += Form("%d",layer);
}
if (isTEC && iTEC==0)
myTitle += TString(" R1-4");
if (isTEC && iTEC>0)
myTitle += TString(" R5-7");
// Save plot to file
std::ostringstream plotName;
plotName << outputDir << "/SurfaceShape_" << subDetName << "_";
plotName << residType;
if (layer!=0)
plotName << "_" << "layer" << layer;
if (isTEC && iTEC==0)
plotName << "_" << "R1-4";
if (isTEC && iTEC>0)
plotName << "_" << "R5-7";
plotName << ".eps";
// Generate histograms with selection
THStack *hs = addHists(selection, residType);
if (!hs || hs->GetHists()==0 || hs->GetHists()->GetSize()==0) {
std::cout << "No histogram for " << subDetName << ", perhaps not enough data?" << std::endl;
continue;
}
hs->SetTitle( myTitle );
hs->Draw("nostack PE");
// Adjust Labels
TH1* firstHisto = (TH1*) hs->GetHists()->First();
TString xName = firstHisto->GetXaxis()->GetTitle();
TString yName = firstHisto->GetYaxis()->GetTitle();
hs->GetHistogram()->GetXaxis()->SetTitleColor( kBlack );
hs->GetHistogram()->GetXaxis()->SetTitle( xName );
hs->GetHistogram()->GetYaxis()->SetTitleColor( kBlack );
hs->GetHistogram()->GetYaxis()->SetTitle( yName );
// Save to file
c.Update();
c.Print(plotName.str().c_str());
}
}
}
return;
}
示例3: ttbar_looseLep2Pt_logy
void ttbar_looseLep2Pt_logy()
{
//=========Macro generated from canvas: c1/c1
//========= (Sun Dec 11 15:16:17 2016) by ROOT version6.06/01
TCanvas *c1 = new TCanvas("c1", "c1",1,1,1200,1416);
gStyle->SetOptStat(0);
gStyle->SetOptTitle(0);
c1->SetHighLightColor(2);
c1->Range(0,0,1,1);
c1->SetFillColor(0);
c1->SetBorderMode(0);
c1->SetBorderSize(2);
c1->SetTickx(1);
c1->SetTicky(1);
c1->SetLeftMargin(0.15);
c1->SetRightMargin(0.05);
c1->SetTopMargin(0.07);
c1->SetBottomMargin(0.13);
c1->SetFrameFillStyle(0);
c1->SetFrameBorderMode(0);
// ------------>Primitives in pad: pad1
TPad *pad1 = new TPad("pad1", "pad1",0,0.3,1,1);
pad1->Draw();
pad1->cd();
pad1->Range(-93.75,-6.459411,531.25,2.538922);
pad1->SetFillColor(0);
pad1->SetBorderMode(0);
pad1->SetBorderSize(2);
pad1->SetLogy();
pad1->SetTickx(1);
pad1->SetTicky(1);
pad1->SetLeftMargin(0.15);
pad1->SetRightMargin(0.05);
pad1->SetTopMargin(0.07);
pad1->SetBottomMargin(0);
pad1->SetFrameFillStyle(0);
pad1->SetFrameBorderMode(0);
pad1->SetFrameFillStyle(0);
pad1->SetFrameBorderMode(0);
THStack *h = new THStack();
h->SetName("h");
h->SetTitle("");
h->SetMinimum(1.61613e-06);
h->SetMaximum(32.94396);
TH1F *h_stack_8 = new TH1F("h_stack_8","",20,0,500);
h_stack_8->SetMinimum(3.472076e-07);
h_stack_8->SetMaximum(81.10342);
h_stack_8->SetDirectory(0);
h_stack_8->SetStats(0);
Int_t ci; // for color index setting
TColor *color; // for color definition with alpha
ci = TColor::GetColor("#000099");
h_stack_8->SetLineColor(ci);
h_stack_8->GetXaxis()->SetLabelFont(42);
h_stack_8->GetXaxis()->SetLabelOffset(0.007);
h_stack_8->GetXaxis()->SetTitleSize(0.05);
h_stack_8->GetXaxis()->SetTickLength(0.025);
h_stack_8->GetXaxis()->SetTitleFont(42);
h_stack_8->GetYaxis()->SetTitle("a.u./25 GeV");
h_stack_8->GetYaxis()->SetLabelFont(42);
h_stack_8->GetYaxis()->SetLabelOffset(0.007);
h_stack_8->GetYaxis()->SetTitleSize(0.05);
h_stack_8->GetYaxis()->SetTickLength(0.025);
h_stack_8->GetYaxis()->SetTitleOffset(1.5);
h_stack_8->GetYaxis()->SetTitleFont(42);
h_stack_8->GetZaxis()->SetLabelFont(42);
h_stack_8->GetZaxis()->SetLabelOffset(0.007);
h_stack_8->GetZaxis()->SetTitleSize(0.05);
h_stack_8->GetZaxis()->SetTickLength(0.025);
h_stack_8->GetZaxis()->SetTitleFont(42);
h->SetHistogram(h_stack_8);
TH1D *h_looseLep2Pt_QCD__85 = new TH1D("h_looseLep2Pt_QCD__85","",20,0,500);
h_looseLep2Pt_QCD__85->SetBinContent(1,0.004168645);
h_looseLep2Pt_QCD__85->SetBinContent(2,0.004299542);
h_looseLep2Pt_QCD__85->SetBinContent(3,0.001765161);
h_looseLep2Pt_QCD__85->SetBinContent(4,0.0008868067);
h_looseLep2Pt_QCD__85->SetBinContent(6,0.0004026872);
h_looseLep2Pt_QCD__85->SetBinContent(7,6.27175e-05);
h_looseLep2Pt_QCD__85->SetBinError(1,0.001669574);
h_looseLep2Pt_QCD__85->SetBinError(2,0.002080688);
h_looseLep2Pt_QCD__85->SetBinError(3,0.001425843);
h_looseLep2Pt_QCD__85->SetBinError(4,0.0005754946);
h_looseLep2Pt_QCD__85->SetBinError(6,0.0004026872);
h_looseLep2Pt_QCD__85->SetBinError(7,4.443558e-05);
h_looseLep2Pt_QCD__85->SetEntries(25);
h_looseLep2Pt_QCD__85->SetStats(0);
ci = TColor::GetColor("#cccccc");
h_looseLep2Pt_QCD__85->SetFillColor(ci);
h_looseLep2Pt_QCD__85->GetXaxis()->SetTitle("Sub-leading lep p_{T} [GeV]");
h_looseLep2Pt_QCD__85->GetXaxis()->SetLabelFont(42);
h_looseLep2Pt_QCD__85->GetXaxis()->SetLabelOffset(0.007);
h_looseLep2Pt_QCD__85->GetXaxis()->SetTitleSize(0.05);
h_looseLep2Pt_QCD__85->GetXaxis()->SetTickLength(0.025);
//.........这里部分代码省略.........
示例4: drawpdgstack
//.........这里部分代码省略.........
double sig_evtsppot = 0;
if(tree2) {
TString draw_str = "";
draw_str += dr;
draw_str += ">>h_sig";
draw_str += binning;
TCanvas * canvas_pdg_temp = new TCanvas("temp");
tree2->Draw(draw_str.Data(),
we.c_str(),
op.c_str());
delete canvas_pdg_temp;
TH1F * hist_sig = (TH1F*)gDirectory->Get("h_sig");
hist_sig->SetLineColor(1);
hist_sig->SetFillColor(kRed+3);
hist_sig->Scale(1. / signal_pot * run_pot);
stack->Add(hist_sig);
legend->AddEntry(hist_sig, ("Signal: "+to_string_with_precision(hist_sig->Integral())).c_str());
sig_evtsppot = hist_sig->Integral();
}
legend->SetHeader(("Total: "+to_string_with_precision((hist->Integral()/background_pot*run_pot + sig_evtsppot))).c_str());
((TLegendEntry*)legend->GetListOfPrimitives()->First())->SetTextAlign(22);
std::vector<int> pdg_vec;
for(int i = 1; i <= hist->GetNbinsX(); ++i) {
if(hist->GetBinContent(i) == 0) continue;
int const pdg = i+hist->GetBinLowEdge(0);
if(!pdg_sign) {
if(std::find(pdg_vec.begin(), pdg_vec.end(), abs(pdg)) != pdg_vec.end())
continue;
pdg_vec.push_back(abs(pdg));
}
TString hname = "";
hname += "h_";
hname += pdg;
TString draw_str = "";
draw_str += dr;
draw_str += ">>h_";
draw_str += pdg;
draw_str += binning;
TString weight_str = "";
weight_str += we;
weight_str += "&&(";
weight_str += which_pdg;
weight_str += "==";
weight_str += pdg;
if(!pdg_sign && pdg < 0) {
weight_str += "||";
weight_str += which_pdg;
weight_str += "==";
weight_str += abs(pdg);
}
weight_str += ")";
TCanvas * canvas_pdg_temp = new TCanvas("temp");
tree->Draw(draw_str.Data(),
weight_str.Data(),
op.c_str());
delete canvas_pdg_temp;
int pdg_temp = pdg;
if(!pdg_sign) pdg_temp = abs(pdg);
pdg_stuff const & pdg_s = get_pdg_stuff(pdg_temp, pdg_sign);
TH1F * hist_pdg = (TH1F*)gDirectory->Get(hname.Data());
hist_pdg->SetLineColor(1);
hist_pdg->SetFillColor(pdg_s._color);
hist_pdg->Scale(1. / background_pot * run_pot);
stack->Add(hist_pdg);
legend->AddEntry(hist_pdg, (pdg_s._particle_name+": "+to_string_with_precision(hist_pdg->Integral())).c_str());
}
TCanvas * canvas = new TCanvas(cname.c_str());
stack->Draw();
stack->SetTitle(title.c_str());
stack->GetXaxis()->SetTitle(xtitle.c_str());
stack->GetXaxis()->CenterTitle();
stack->GetYaxis()->SetTitle(ytitle.c_str());
stack->GetYaxis()->CenterTitle();
legend->Draw();
canvas->Write();
delete stack;
delete legend;
delete canvas;
delete hist;
}
示例5: plot_config_combsignal_category_monojet
void plot_config_combsignal_category_monojet()
{
//=========Macro generated from canvas: c_0/c_0
//========= (Wed Mar 2 17:34:36 2016) by ROOT version6.07/03
TCanvas *c_0 = new TCanvas("c_0", "c_0",0,0,800,800);
gStyle->SetOptStat(0);
c_0->SetHighLightColor(2);
c_0->Range(0,0,1,1);
c_0->SetFillColor(0);
c_0->SetBorderMode(0);
c_0->SetBorderSize(2);
c_0->SetFrameBorderMode(0);
// ------------>Primitives in pad: p1
TPad *p1 = new TPad("p1", "p1",0,0.28,1,1);
p1->Draw();
p1->cd();
p1->Range(99.99999,-1.766386,1100,4.975187);
p1->SetFillColor(0);
p1->SetBorderMode(0);
p1->SetBorderSize(2);
p1->SetLogy();
p1->SetBottomMargin(0.01);
p1->SetFrameBorderMode(0);
p1->SetFrameBorderMode(0);
Double_t xAxis1[17] = {200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000};
TH1F *QCD_FITTY__1 = new TH1F("QCD_FITTY__1","",16, xAxis1);
QCD_FITTY__1->SetBinContent(1,5.692051);
QCD_FITTY__1->SetBinContent(2,0.6079234);
QCD_FITTY__1->SetBinContent(3,0.1364834);
QCD_FITTY__1->SetBinContent(5,0.1015811);
QCD_FITTY__1->SetBinError(1,4.740265);
QCD_FITTY__1->SetBinError(2,0.2887402);
QCD_FITTY__1->SetBinError(3,0.1318165);
QCD_FITTY__1->SetBinError(5,0.1015811);
QCD_FITTY__1->SetMinimum(0.02);
QCD_FITTY__1->SetMaximum(20000);
QCD_FITTY__1->SetEntries(93114);
TF1 *func1 = new TF1("func","[0]*(TMath::Exp(-[1]*x))",200,1000);
func1->SetFillColor(19);
func1->SetFillStyle(0);
func1->SetLineColor(2);
func1->SetLineWidth(2);
func1->SetChisquare(1.944907);
func1->SetNDF(14);
func1->GetXaxis()->SetLabelFont(42);
func1->GetXaxis()->SetLabelSize(0.035);
func1->GetXaxis()->SetTitleSize(0.035);
func1->GetXaxis()->SetTitleFont(42);
func1->GetYaxis()->SetLabelFont(42);
func1->GetYaxis()->SetLabelSize(0.035);
func1->GetYaxis()->SetTitleSize(0.035);
func1->GetYaxis()->SetTitleFont(42);
func1->SetParameter(0,18385.94);
func1->SetParError(0,68314.65);
func1->SetParLimits(0,0,0);
func1->SetParameter(1,0.03609646);
func1->SetParError(1,0.01573978);
func1->SetParLimits(1,0,0);
QCD_FITTY__1->GetListOfFunctions()->Add(func1);
Int_t ci; // for color index setting
TColor *color; // for color definition with alpha
ci = TColor::GetColor("#000099");
QCD_FITTY__1->SetLineColor(ci);
QCD_FITTY__1->GetXaxis()->SetLabelFont(42);
QCD_FITTY__1->GetXaxis()->SetLabelSize(0);
QCD_FITTY__1->GetXaxis()->SetTitleSize(0.035);
QCD_FITTY__1->GetXaxis()->SetTitleFont(42);
QCD_FITTY__1->GetYaxis()->SetTitle("Events/GeV");
QCD_FITTY__1->GetYaxis()->SetLabelFont(42);
QCD_FITTY__1->GetYaxis()->SetLabelSize(0.045);
QCD_FITTY__1->GetYaxis()->SetTitleSize(0.05);
QCD_FITTY__1->GetYaxis()->SetTitleOffset(0.9);
QCD_FITTY__1->GetYaxis()->SetTitleFont(42);
QCD_FITTY__1->GetZaxis()->SetLabelFont(42);
QCD_FITTY__1->GetZaxis()->SetLabelSize(0.035);
QCD_FITTY__1->GetZaxis()->SetTitleSize(0.035);
QCD_FITTY__1->GetZaxis()->SetTitleFont(42);
QCD_FITTY__1->Draw("");
THStack *bkg = new THStack();
bkg->SetName("bkg");
bkg->SetTitle("");
Double_t xAxis2[17] = {200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000};
TH1F *bkg_stack_1 = new TH1F("bkg_stack_1","",16, xAxis2);
bkg_stack_1->SetMinimum(0.4825172);
bkg_stack_1->SetMaximum(1930.069);
bkg_stack_1->SetDirectory(0);
bkg_stack_1->SetStats(0);
ci = TColor::GetColor("#000099");
bkg_stack_1->SetLineColor(ci);
bkg_stack_1->GetXaxis()->SetLabelFont(42);
bkg_stack_1->GetXaxis()->SetLabelSize(0.035);
bkg_stack_1->GetXaxis()->SetTitleSize(0.035);
bkg_stack_1->GetXaxis()->SetTitleFont(42);
//.........这里部分代码省略.........
示例6: plot_MC_noRatio_wError
// *************************************** //
// this is a function that takes a set of //
// histograms and draws them on a canvas //
// in a stack, returning the canvas //
// just for MC- no ratio and no data. //
// This one includes syst and stat or just //
// stat errors //
// *************************************** //
TCanvas* drawPlots::plot_MC_noRatio_wError(std::vector<TH1D*> histos, std::vector<std::string> names, std::string axisName, TH1D* signal, TH1D* errDown, TH1D* errUp){
const unsigned int MAINPLOT_WIDTH = 800;
const unsigned int MAINPLOT_HEIGHT = 600;
TCanvas* canvas = new TCanvas("canvas","canvas",0,0,MAINPLOT_WIDTH,MAINPLOT_HEIGHT);
canvas->SetMargin(0.,0.,0.,0.);
canvas->cd();
double main_y_max = -99;
double main_y_min = -99;
double main_x_max = -99;
double main_x_min = -99;
for(int a=0; a<histos.size(); a++){
GetAxisLimits(histos[a], main_x_min, main_x_max, main_y_min, main_y_max);
}
// create main pad
TPad* mainPad = new TPad("main","main",0.,0.,1.,1.);
mainPad->SetMargin(0.15,0.05,0.15,.05); // left, right, bottom, top
mainPad->Draw();
mainPad->cd();
SetAtlasStyle();
THStack* Stack = new THStack();
std::string title = std::string(";") + axisName + ";Events";
Stack->SetTitle(title.c_str());
for(int b=0; b<histos.size(); b++){
histos[b]->SetLineColor(1);
histos[b]->SetFillColor(tools::setColor(names[b]));
Stack->Add(histos[b]);
}
main_y_max = main_y_max*1.5;
Stack->SetMaximum(main_y_max);
Stack->Draw("hist");
errDown->Draw("E2same");
errUp->Draw("E2Same");
signal->SetLineStyle(2);
signal->SetLineColor(kRed);
signal->Draw("hist same");
TLegend* leg = new TLegend(0.7,0.7,0.93,0.9);
leg->SetFillStyle(0);
leg->SetBorderSize(0);
leg->AddEntry(signal, "Signal", "f");
for(int q=0; q<histos.size(); q++){
leg->AddEntry(histos[q], names[q].c_str(), "f");
}
leg->Draw("lpe");
ATLAS_LABEL(0.2,0.85,1);
char text[]="#sqrt{s}=8 TeV";
myText(0.2,0.7,1,text);
return canvas;
}
示例7: plotAll
// *************************************** //
// this is a function that takes a set of //
// histograms and draws them on a canvas //
// in a stack, returning the canvas. //
// It also plots the signal as a dashed //
// line and the data with a ratio at the //
// the bottom of data/allBackgrounds //
// *************************************** //
TCanvas* drawPlots::plotAll(std::vector<TH1D*> histos, std::vector<std::string> names, std::string axisName, TH1D* signal, TH1D* data, TH1D* errDown, TH1D* errUp, bool isSignalRegion, bool doLogAxis){
const unsigned int MAINPLOT_WIDTH = 800;
const unsigned int MAINPLOT_HEIGHT = 500;
const unsigned int RATIOPLOT_HEIGHT = 125;
const unsigned int OFFSET = 10;
//LUKE: Title offset and title size are proportional in
//root, so you have to change them together,
//this makes me a sad panda
const double RATIOPLOT_YAXIS_TITLE_OFFSET = 0.4;
const double RATIOPLOT_YAXIS_TITLE_SIZE = 0.14;
const double RATIOPLOT_YAXIS_TICK_LENGTH = 0.01;
const double RATIOPLOT_YAXIS_LABEL_SIZE = 0.15;
const double RATIOPLOT_XAXIS_TITLE_OFFSET = 0.9;
const double RATIOPLOT_XAXIS_TITLE_SIZE = 0.2;
const double RATIOPLOT_XAXIS_TICK_LENGTH = 0.05;
const double RATIOPLOT_XAXIS_LABEL_SIZE = 0.2;
const double CANVAS_HEIGHT = MAINPLOT_HEIGHT+RATIOPLOT_HEIGHT+OFFSET;
TCanvas* canvas = new TCanvas("canvas","canvas",0,0,MAINPLOT_WIDTH,CANVAS_HEIGHT);
canvas->SetMargin(0.,0.,0.,0.);
canvas->Clear();
canvas->cd();
// create main pad
const double mainPad_ylow = (CANVAS_HEIGHT - MAINPLOT_HEIGHT)/CANVAS_HEIGHT;
const double mainPad_yhigh = 1.;
const double pad_margin_left = 0.15;
const double pad_margin_right = 0.05;
double main_y_max = -99;
double main_y_min = -99;
double main_x_max = -99;
double main_x_min = -99;
for(int a=0; a<histos.size(); a++){
if(histos[a]){
if(histos[a]->GetEntries()> 0.){
GetAxisLimits(histos[a], main_x_min, main_x_max, main_y_min, main_y_max);
}
}
}
if(data){
int maxBinData = data->GetMaximumBin();
double dataYmax = data->GetBinContent(maxBinData);
if(dataYmax > main_y_max) main_y_max = dataYmax;
}
// create main pad
TPad* mainPad = new TPad("main","main",0.,mainPad_ylow,1.,mainPad_yhigh);
mainPad->SetMargin(pad_margin_left,pad_margin_right,0.,.05); // left, right, bottom, top
mainPad->Draw();
mainPad->cd();
SetAtlasStyle();
if(doLogAxis)mainPad->SetLogy();
// clone signal or data because one should exist for each plot
TH1D* allBackgrounds;
bool gotSomething=false;
if(signal)
allBackgrounds = (TH1D*)signal->Clone("all_backgrounds");
else if(data)
allBackgrounds = (TH1D*)data->Clone("all_backgrounds");
else{
for(int b=0; b<histos.size(); b++){
if(histos[b] && !gotSomething){
allBackgrounds = (TH1D*)histos[b]->Clone("all_backgrounds");
gotSomething=true;
}
}
}
// set all bins to zero so that you can add all histograms to it
for(int i=0; i<=allBackgrounds->GetNbinsX()+1; i++)
allBackgrounds->SetBinContent(i,0);
THStack* Stack = new THStack();
std::string title = std::string(";") + axisName + ";Events";
Stack->SetTitle(title.c_str());
for(int b=0; b<histos.size(); b++){
if(histos[b]){
if(histos[b]->GetEntries() > 0.){
histos[b]->SetLineColor(1);
histos[b]->SetFillColor(tools::setColor(names[b]));
//.........这里部分代码省略.........
示例8: plotHists
TCanvas* plotHists(vector<TH1*> histogramsToPlot, vector<TString> histogramLabels, TString title="", TString xTitle="", TString yTitle="", bool areaNormalize=false) {
//*************************************************
// Variables
bool plotLogY = true; // false = no log; true = log
vector<int> histColors;
histColors.push_back(kBlack); // change colors as you like
histColors.push_back(kBlue);
histColors.push_back(kRed);
histColors.push_back(kGreen-1);
float histLineWidth = 2.0;
bool useMarkers = true; // search online for TAttMarker
vector<int> histMarkerStyles; // to see all available markers
histMarkerStyles.push_back( 20 );
histMarkerStyles.push_back( 22 );
histMarkerStyles.push_back( 21 );
histMarkerStyles.push_back( 23 );
float histMarkerSize = 0.9;
int plotWidth=600;
int plotHeight=600;
// END of Variables
//*************************************************
// Create the canvas
TCanvas *c1 = new TCanvas("c1", "c1",0,0,plotWidth,plotHeight);
// Turn off stats box
gStyle->SetOptStat(0);
// Create copies of histograms provided
// and area normalize, if requested
vector<TH1*> hists;
for (int i=0; i<histogramsToPlot.size(); i++) {
hists.push_back( (TH1*)histogramsToPlot[i]->Clone() );
if (areaNormalize) {
Double_t integral = hists[i]->Integral();
if (integral>0.0) hists[i]->Scale(1/integral);
}
}
// Set histogram plotting variables
// and add them to the histogram stack & legend
THStack *tempStack = new THStack();
TLegend *infoBox = new TLegend(0.65, 0.70, 0.90, 0.85, "");
for (int i=0; i<histogramsToPlot.size(); i++) {
hists[i]->SetLineColor(histColors[i]);
hists[i]->SetLineWidth(histLineWidth);
if (useMarkers) {
hists[i]->SetMarkerStyle(histMarkerStyles[i]);
hists[i]->SetMarkerColor(histColors[i]);
hists[i]->SetMarkerSize(histMarkerSize);
}
infoBox->AddEntry(hists[i],histogramLabels[i],"LP");
tempStack->Add(hists[i]);
}
// Draw the stack of histograms
tempStack->Draw("nostack");
// Set title/label sizes and offsets
tempStack->GetXaxis()->SetTitleOffset(0.9);
tempStack->GetYaxis()->SetTitleOffset(1.2);
tempStack->GetXaxis()->SetLabelSize(0.04);
tempStack->GetYaxis()->SetLabelSize(0.05);
tempStack->GetXaxis()->SetTitleSize(0.06);
tempStack->GetYaxis()->SetTitleSize(0.05);
// Set axis titles
tempStack->SetTitle(title+";"+xTitle+";"+yTitle);
// Draw legend as long as the labels aren't empty
infoBox->SetShadowColor(0); // 0 = transparent
infoBox->SetLineColor(0);
infoBox->SetFillStyle(0);
if (histogramLabels[0]!="") {
infoBox->Draw();
}
c1->SetLogy(plotLogY);
return c1;
}
示例9: plot
void plot(int mass) {
double myQCDRelUncert = 0.038;
double myEWKRelUncert = 0.131;
double myFakesRelUncert = 0.238;
double delta = 1.4;
double br = 0.05;
bool debug = false;
bool log = false;
double ymin = 0.001;
double ymax = 48;
static bool bMessage = false;
if (!bMessage) {
cout << "Values used as relative uncertainty (please check):" << endl;
cout << " QCD: " << myQCDRelUncert << endl;
cout << " EWK genuine tau: " << myEWKRelUncert << endl;
cout << " EWK fake tau: " << myFakesRelUncert << endl << endl;
bMessage = true;
}
cout << "Processing mass point: " << mass << " GeV/c2" << endl;
gStyle->SetOptFit(1);
gStyle->SetOptStat(0);
gStyle->SetOptTitle(0);
gStyle->SetTitleFont(43, "xyz");
gStyle->SetTitleSize(33, "xyz");
gStyle->SetLabelFont(43, "xyz");
gStyle->SetLabelSize(27, "xyz");
//std::string infile = "EPS_data_nodeltaphi/hplus_100.root";
//std::string infile = "EPS_data_deltaphi160/hplus_100.root";
std::stringstream s;
s << "lands_histograms_hplushadronic_m" << mass << ".root";
std::string infile = s.str();
// Canvas
TCanvas *myCanvas = new TCanvas("myCanvas", "",0,0,600,600);
myCanvas->SetHighLightColor(2);
myCanvas->Range(0,0,1,1);
myCanvas->SetFillColor(0);
myCanvas->SetBorderMode(0);
myCanvas->SetBorderSize(2);
if (log)
myCanvas->SetLogy();
myCanvas->SetTickx(1);
myCanvas->SetTicky(1);
myCanvas->SetLeftMargin(0.16);
myCanvas->SetRightMargin(0.05);
myCanvas->SetTopMargin(0.05);
myCanvas->SetBottomMargin(0.08);
myCanvas->SetFrameFillStyle(0);
myCanvas->SetFrameBorderMode(0);
myCanvas->SetFrameFillStyle(0);
myCanvas->SetFrameBorderMode(0);
myCanvas->cd();
Int_t ci;
TFile* f = TFile::Open(infile.c_str());
s.str("");
s << "HW" << mass << "_1";
TH1* hw = (TH1*)f->Get(s.str().c_str());
s.str("");
s << "HH" << mass << "_1";
TH1* hh = (TH1*)f->Get(s.str().c_str());
TH1* data = (TH1*)f->Get("data_obs");
data->SetLineWidth(2);
data->SetMarkerStyle(20);
data->SetMarkerSize(1.2);
TH1* ewktau = (TH1*)f->Get("EWK_Tau");
ci = TColor::GetColor("#993399");
ewktau->SetFillColor(ci);
ewktau->SetLineWidth(0);
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
//.........这里部分代码省略.........
示例10: plotStack
void stackPlotter::plotStack(const TString& key, legendposition legpos) {
if(debug)
std::cout << "stackPlotter::plotStack" << std::endl;
std::vector<std::pair<Int_t,TH1*> > legEntries = stacksLegEntries_[key];
if(legEntries.size()<1) return;
TCanvas *c = new TCanvas(key,key,800,600);
TLegend *leg = new TLegend(0.75,0.75,0.95,0.95); //will be overwritten by style!
THStack *stack = new THStack();
//determine legend position TBI (add all histos, look at mean and max values etc)
//float max=stack->GetMaximum(); //unfortunately no mean function also not filled, yet.
//needs another loop on histos
TH1 * h=(TH1 *) legEntries.at(0).second->Clone();
for(size_t i=1;i<legEntries.size();i++){
h->Add(legEntries.at(i).second);
}
// int maxbin=h->GetMaximumBin();
//int minbin=h->GetMinimumBin();
// float ymax=h->GetBinContent(maxbin);
//float ymin=h->GetBinContent(minbin);
//pass this to the style functions
delete h;
//gStyle->SetOptTitle(0);//no title
for(size_t i=0; i < legEntries.size(); i++) {
TString legName = legEntries.at(i).second->GetName();
if(legName == "") continue;
applyStyleToTH1(legEntries.at(i).second,legpos);
stack->Add(legEntries.at(i).second,"HIST");
stack->SetTitle("");//legEntries.at(i).second->GetTitle());
stack->SetName(legEntries.at(i).second->GetTitle());
//mirror entry for legend
leg->AddEntry(legEntries.at(legEntries.size()-1-i).second,
legEntries.at(legEntries.size()-1-i).second->GetName(),
"F");
}
// draw plot and legend
c->cd();
applyStyleToCanvas(c,legpos);
stack->Draw();
stack->GetXaxis()->SetTitle(legEntries.at(0).second->GetXaxis()->GetTitle());
stack->GetYaxis()->SetTitle(legEntries.at(0).second->GetYaxis()->GetTitle());
applyStyleToAxis(stack,legpos);
applyStyleToLegend(leg,legpos);
stack->Draw();
leg->Draw();
//c->BuildLegend();
// save and exit
if(saveplots_) {
c->SaveAs(outdir_+"/"+key+".pdf");
c->SaveAs(outdir_+"/"+key+".png");
}
if(savecanvases_ && outfile_) {
outfile_->cd();
c->Write();
}
delete stack;
delete leg;
delete c;
}
示例11: ttbar_nJet
void ttbar_nJet()
{
//=========Macro generated from canvas: c1/c1
//========= (Sun Dec 11 15:16:19 2016) by ROOT version6.06/01
TCanvas *c1 = new TCanvas("c1", "c1",1,1,1200,1416);
gStyle->SetOptStat(0);
gStyle->SetOptTitle(0);
c1->SetHighLightColor(2);
c1->Range(0,0,1,1);
c1->SetFillColor(0);
c1->SetBorderMode(0);
c1->SetBorderSize(2);
c1->SetTickx(1);
c1->SetTicky(1);
c1->SetLeftMargin(0.15);
c1->SetRightMargin(0.05);
c1->SetTopMargin(0.07);
c1->SetBottomMargin(0.13);
c1->SetFrameFillStyle(0);
c1->SetFrameBorderMode(0);
// ------------>Primitives in pad: pad1
TPad *pad1 = new TPad("pad1", "pad1",0,0.3,1,1);
pad1->Draw();
pad1->cd();
pad1->Range(-2.1875,0,9.0625,0.5878968);
pad1->SetFillColor(0);
pad1->SetBorderMode(0);
pad1->SetBorderSize(2);
pad1->SetTickx(1);
pad1->SetTicky(1);
pad1->SetLeftMargin(0.15);
pad1->SetRightMargin(0.05);
pad1->SetTopMargin(0.07);
pad1->SetBottomMargin(0);
pad1->SetFrameFillStyle(0);
pad1->SetFrameBorderMode(0);
pad1->SetFrameFillStyle(0);
pad1->SetFrameBorderMode(0);
THStack *h = new THStack();
h->SetName("h");
h->SetTitle("");
h->SetMinimum(0);
h->SetMaximum(0.5207086);
TH1F *h_stack_19 = new TH1F("h_stack_19","",9,-0.5,8.5);
h_stack_19->SetMinimum(0);
h_stack_19->SetMaximum(0.546744);
h_stack_19->SetDirectory(0);
h_stack_19->SetStats(0);
Int_t ci; // for color index setting
TColor *color; // for color definition with alpha
ci = TColor::GetColor("#000099");
h_stack_19->SetLineColor(ci);
h_stack_19->GetXaxis()->SetLabelFont(42);
h_stack_19->GetXaxis()->SetLabelOffset(0.007);
h_stack_19->GetXaxis()->SetTitleSize(0.05);
h_stack_19->GetXaxis()->SetTickLength(0.025);
h_stack_19->GetXaxis()->SetTitleFont(42);
h_stack_19->GetYaxis()->SetTitle("a.u.");
h_stack_19->GetYaxis()->SetLabelFont(42);
h_stack_19->GetYaxis()->SetLabelOffset(0.007);
h_stack_19->GetYaxis()->SetTitleSize(0.05);
h_stack_19->GetYaxis()->SetTickLength(0.025);
h_stack_19->GetYaxis()->SetTitleOffset(1.5);
h_stack_19->GetYaxis()->SetTitleFont(42);
h_stack_19->GetZaxis()->SetLabelFont(42);
h_stack_19->GetZaxis()->SetLabelOffset(0.007);
h_stack_19->GetZaxis()->SetTitleSize(0.05);
h_stack_19->GetZaxis()->SetTickLength(0.025);
h_stack_19->GetZaxis()->SetTitleFont(42);
h->SetHistogram(h_stack_19);
TH1D *h_nJet_QCD__217 = new TH1D("h_nJet_QCD__217","",9,-0.5,8.5);
h_nJet_QCD__217->SetBinContent(2,0.001991738);
h_nJet_QCD__217->SetBinContent(3,0.0005078625);
h_nJet_QCD__217->SetBinContent(4,0.006489724);
h_nJet_QCD__217->SetBinContent(5,0.001899386);
h_nJet_QCD__217->SetBinContent(6,0.000696849);
h_nJet_QCD__217->SetBinError(2,0.001424948);
h_nJet_QCD__217->SetBinError(3,0.0005078625);
h_nJet_QCD__217->SetBinError(4,0.00246407);
h_nJet_QCD__217->SetBinError(5,0.001037545);
h_nJet_QCD__217->SetBinError(6,0.0004566736);
h_nJet_QCD__217->SetEntries(25);
h_nJet_QCD__217->SetStats(0);
ci = TColor::GetColor("#cccccc");
h_nJet_QCD__217->SetFillColor(ci);
h_nJet_QCD__217->GetXaxis()->SetTitle("N_{jet}");
h_nJet_QCD__217->GetXaxis()->SetLabelFont(42);
h_nJet_QCD__217->GetXaxis()->SetLabelOffset(0.007);
h_nJet_QCD__217->GetXaxis()->SetTitleSize(0.05);
h_nJet_QCD__217->GetXaxis()->SetTickLength(0.025);
h_nJet_QCD__217->GetXaxis()->SetTitleFont(42);
h_nJet_QCD__217->GetYaxis()->SetTitle("a.u.");
h_nJet_QCD__217->GetYaxis()->SetLabelFont(42);
//.........这里部分代码省略.........
示例12: scatterplot
void scatterplot() {
double yPos, xPos, theta, energy = 0.; // NOTE: theta comes in degrees
int numHit, pID = 0;
// Initialize histograms
double nEnergyMin = 10; // MeV
double nEnergyMax = 510; // MeV
int nEnergyBins = 50;
double dEnergyBinSize = (double)(nEnergyMax - nEnergyMin) / (double)nEnergyBins;
double nThetaMin = 34; // mrad
double nThetaMax = 88; // mrad
int nThetaBins = 50;
double dThetaBinSize = (nThetaMax - nThetaMin) / nThetaBins;
double nM2Min = -5000; // MeV
double nM2Max = 5000; // MeV
int nM2Bins = 100;
double dM2BinSize = (nM2Max - nM2Min)/nM2Bins;
THStack *hs = new THStack("hs","Scatterplot");
TH2F* henergythetayy = new TH2F("scatter4", // plot label
"e+e- > yy", // title
nThetaBins, // x num of bins
nThetaMin, // x min
nThetaMax, // x max
nEnergyBins, // y num of bins
nEnergyMin, // y min
nEnergyMax); // y max
henergythetayy->SetMarkerColor(kBlue);
henergythetayy->SetMarkerStyle(21);
henergythetayy->SetMarkerSize(1.);
TFile* file = new TFile("e+e-2yyGUN.root");
TTree* Hits_Info = (TTree *)file->Get("Signal");
Hits_Info->SetBranchAddress("numHits", &numHit);
Hits_Info->SetBranchAddress("energyTot", &energy);
Hits_Info->SetBranchAddress("XPosition", &xPos);
Hits_Info->SetBranchAddress("YPosition", &yPos);
Hits_Info->SetBranchAddress("Particle_ID", &pID);
Hits_Info->SetBranchAddress("Theta", &theta);
// go through all entries and fill the histograms
int nentries = Hits_Info->GetEntries();
for (int i=0; i<nentries; i++) {
Hits_Info->GetEntry(i);
if (pID == 22 && i < (XSECyy * SCAT_NORM)) { // gammas only
theta*= TMath::Pi()/180; //radians
cout << "M^2 is: " << mSquared(energy, theta) << endl;
cout << "Energy is: " << energy << endl;
henergythetayy->Fill(theta*1000, energy);
}
}
cout << "DM2binsize is:" << dM2BinSize << endl;
//henergythetayy->SetFillColor(kBlue);
//hmyy->SetFillStyle(3001);
henergythetayy->GetXaxis()->SetTitle("#theta");
henergythetayy->GetYaxis()->SetTitle("Energy (MeV)");
henergythetayy->GetXaxis()->CenterTitle();
henergythetayy->GetYaxis()->CenterTitle();
//hmyy->GetYaxis()->SetTitle("Photons per MeV^{2} per Second (MeV^{-2} s^{-1})");
//hmyy->GetXaxis()->CenterTitle();
//hmyy->GetYaxis()->CenterTitle();
hs->Add(henergythetayy);
TFile* fileyyy = new TFile("e+e-2yyyGUN.root");
TTree* Hits_Infoyyy = (TTree *)fileyyy->Get("Signal");
Hits_Infoyyy->SetBranchAddress("numHits", &numHit);
Hits_Infoyyy->SetBranchAddress("energyTot", &energy);
Hits_Infoyyy->SetBranchAddress("XPosition", &xPos);
Hits_Infoyyy->SetBranchAddress("YPosition", &yPos);
Hits_Infoyyy->SetBranchAddress("Particle_ID", &pID);
Hits_Infoyyy->SetBranchAddress("Theta", &theta);
TH2F* henergythetayyy = new TH2F("scatter3", // plot label
"e+e- > yyy", // title
nThetaBins, // x num of bins
nThetaMin, // x min
nThetaMax, // x max
nEnergyBins, // y num of bins
nEnergyMin, // y min
nEnergyMax); // y max
henergythetayyy->SetMarkerColor(kRed);
henergythetayyy->SetMarkerStyle(20);
henergythetayyy->SetMarkerSize(1.);
//.........这里部分代码省略.........
示例13: ttbar_jet1CSV
void ttbar_jet1CSV()
{
//=========Macro generated from canvas: c1/c1
//========= (Sun Dec 11 15:16:19 2016) by ROOT version6.06/01
TCanvas *c1 = new TCanvas("c1", "c1",1,1,1200,1416);
gStyle->SetOptStat(0);
gStyle->SetOptTitle(0);
c1->SetHighLightColor(2);
c1->Range(0,0,1,1);
c1->SetFillColor(0);
c1->SetBorderMode(0);
c1->SetBorderSize(2);
c1->SetTickx(1);
c1->SetTicky(1);
c1->SetLeftMargin(0.15);
c1->SetRightMargin(0.05);
c1->SetTopMargin(0.07);
c1->SetBottomMargin(0.13);
c1->SetFrameFillStyle(0);
c1->SetFrameBorderMode(0);
// ------------>Primitives in pad: pad1
TPad *pad1 = new TPad("pad1", "pad1",0,0.3,1,1);
pad1->Draw();
pad1->cd();
pad1->Range(-0.1875,0,1.0625,0.5424993);
pad1->SetFillColor(0);
pad1->SetBorderMode(0);
pad1->SetBorderSize(2);
pad1->SetTickx(1);
pad1->SetTicky(1);
pad1->SetLeftMargin(0.15);
pad1->SetRightMargin(0.05);
pad1->SetTopMargin(0.07);
pad1->SetBottomMargin(0);
pad1->SetFrameFillStyle(0);
pad1->SetFrameBorderMode(0);
pad1->SetFrameFillStyle(0);
pad1->SetFrameBorderMode(0);
THStack *h = new THStack();
h->SetName("h");
h->SetTitle("");
h->SetMinimum(0);
h->SetMaximum(0.4804993);
TH1F *h_stack_21 = new TH1F("h_stack_21","",10,0,1);
h_stack_21->SetMinimum(0);
h_stack_21->SetMaximum(0.5045243);
h_stack_21->SetDirectory(0);
h_stack_21->SetStats(0);
Int_t ci; // for color index setting
TColor *color; // for color definition with alpha
ci = TColor::GetColor("#000099");
h_stack_21->SetLineColor(ci);
h_stack_21->GetXaxis()->SetLabelFont(42);
h_stack_21->GetXaxis()->SetLabelOffset(0.007);
h_stack_21->GetXaxis()->SetTitleSize(0.05);
h_stack_21->GetXaxis()->SetTickLength(0.025);
h_stack_21->GetXaxis()->SetTitleFont(42);
h_stack_21->GetYaxis()->SetTitle("a.u.");
h_stack_21->GetYaxis()->SetLabelFont(42);
h_stack_21->GetYaxis()->SetLabelOffset(0.007);
h_stack_21->GetYaxis()->SetTitleSize(0.05);
h_stack_21->GetYaxis()->SetTickLength(0.025);
h_stack_21->GetYaxis()->SetTitleOffset(1.5);
h_stack_21->GetYaxis()->SetTitleFont(42);
h_stack_21->GetZaxis()->SetLabelFont(42);
h_stack_21->GetZaxis()->SetLabelOffset(0.007);
h_stack_21->GetZaxis()->SetTitleSize(0.05);
h_stack_21->GetZaxis()->SetTickLength(0.025);
h_stack_21->GetZaxis()->SetTitleFont(42);
h->SetHistogram(h_stack_21);
TH1D *h_jet1CSV_QCD__241 = new TH1D("h_jet1CSV_QCD__241","",10,0,1);
h_jet1CSV_QCD__241->SetBinContent(1,0.001669958);
h_jet1CSV_QCD__241->SetBinContent(2,0.001297151);
h_jet1CSV_QCD__241->SetBinContent(3,0.0001985037);
h_jet1CSV_QCD__241->SetBinContent(4,0.001317617);
h_jet1CSV_QCD__241->SetBinContent(5,0.001460061);
h_jet1CSV_QCD__241->SetBinContent(6,0.0005098467);
h_jet1CSV_QCD__241->SetBinContent(8,9.216642e-05);
h_jet1CSV_QCD__241->SetBinContent(10,0.005040257);
h_jet1CSV_QCD__241->SetBinError(1,0.001015339);
h_jet1CSV_QCD__241->SetBinError(2,0.0006375418);
h_jet1CSV_QCD__241->SetBinError(3,0.0001985037);
h_jet1CSV_QCD__241->SetBinError(4,0.0007758122);
h_jet1CSV_QCD__241->SetBinError(5,0.0009604397);
h_jet1CSV_QCD__241->SetBinError(6,0.0005098467);
h_jet1CSV_QCD__241->SetBinError(8,9.216642e-05);
h_jet1CSV_QCD__241->SetBinError(10,0.002524985);
h_jet1CSV_QCD__241->SetEntries(25);
h_jet1CSV_QCD__241->SetStats(0);
ci = TColor::GetColor("#cccccc");
h_jet1CSV_QCD__241->SetFillColor(ci);
h_jet1CSV_QCD__241->GetXaxis()->SetTitle("jet 1 CSV");
h_jet1CSV_QCD__241->GetXaxis()->SetLabelFont(42);
//.........这里部分代码省略.........
示例14: draw_from_trees
//.........这里部分代码省略.........
hother->SetBinError(nbinsx, e_overflow);
i_overflow=ht1bbbb_1500_100->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
ht1bbbb_1500_100->SetBinContent(nbinsx, i_overflow);
ht1bbbb_1500_100->SetBinError(nbinsx, e_overflow);
i_overflow=ht1bbbb_1000_900->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
ht1bbbb_1000_900->SetBinContent(nbinsx, i_overflow);
ht1bbbb_1000_900->SetBinError(nbinsx, e_overflow);
i_overflow=ht1tttt_1500_100->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
ht1tttt_1500_100->SetBinContent(nbinsx, i_overflow);
ht1tttt_1500_100->SetBinError(nbinsx, e_overflow);
i_overflow=ht1tttt_1200_800->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
ht1tttt_1200_800->SetBinContent(nbinsx, i_overflow);
ht1tttt_1200_800->SetBinError(nbinsx, e_overflow);
i_overflow=ht1qqqq_1400_100->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
ht1qqqq_1400_100->SetBinContent(nbinsx, i_overflow);
ht1qqqq_1400_100->SetBinError(nbinsx, e_overflow);
i_overflow=ht1qqqq_1000_800->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
ht1qqqq_1000_800->SetBinContent(nbinsx, i_overflow);
ht1qqqq_1000_800->SetBinError(nbinsx, e_overflow);
}
// Add up MC histograms
hmc_exp->Add(httbar);
hmc_exp->Add(hqcd);
hmc_exp->Add(hznn);
hmc_exp->Add(hwjets);
hmc_exp->Add(hsingle_top);
hmc_exp->Add(hother);
double binwidth = (xup - xlow) / nbinsx;
TString ytitle = Form("Events / %.3f", binwidth);
hmc_exp->GetXaxis()->SetTitle(httbar->GetXaxis()->GetTitle());
hmc_exp->GetYaxis()->SetTitle(ytitle);
cout << "... DONE: add all backgrounds to mc_exp." << endl;
Double_t ttbar_e(0.), qcd_e(0.), znn_e(0.), wjets_e(0.), other_e(0.), single_top_e(0.), bg_tot_e(0.), t1tttt_1500_100_e(0.);
double ttbar_n(httbar->IntegralAndError(0,nbinsx+1, ttbar_e));
double qcd_n(hqcd->IntegralAndError(0,nbinsx+1, qcd_e));
double znn_n(hznn->IntegralAndError(0,nbinsx+1, znn_e));
double wjets_n(hwjets->IntegralAndError(0,nbinsx+1, wjets_e));
double other_n(hother->IntegralAndError(0,nbinsx+1, other_e));
double single_top_n(hsingle_top->IntegralAndError(0,nbinsx+1, single_top_e));
double bg_tot(hmc_exp->IntegralAndError(0,nbinsx+1, bg_tot_e));
double t1tttt_1500_100_n(ht1tttt_1500_100->IntegralAndError(0,nbinsx+1, t1tttt_1500_100_e));
printf("Counts before cut: %s\n",var.Data());
printf("&ttbar&qcd&znn&wjets&single top&other&t1bbbb_1500_100\\\\ \n");
printf("%s & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f \\\\\n",
var.Data(),
ttbar_n,ttbar_e,
qcd_n,qcd_e,
znn_n,znn_e,
wjets_n,wjets_e,
single_top_n,single_top_e,
other_n,other_e,
// hmc_exp->GetBinContent(1), hmc_exp->GetBinError(1),
bg_tot,bg_tot_e,
t1tttt_1500_100_n,t1tttt_1500_100_e);
cout << "... DONE: filled histograms." << endl;
if (sigStack) {
示例15: GetStack
THStack* BasePlot::GetStack(bool isLog) {
THStack* hstack = new THStack();
float binWidth = 0;
for (int i=0; i<nSamples; i++) if( _hist[i] && i != iHWW) {
_hist[i]->SetLineColor(sampleColor[i]);
_hist[i]->SetFillColor(sampleColor[i]);
_hist[i]->SetFillStyle(1001);
binWidth = _hist[i]->GetBinWidth(1);
hstack->Add(_hist[i]);
}
for (size_t i=0; i<_autreHists.size(); i++) {
_autreHists[i].second->SetLineColor(autreColors[i]);
_autreHists[i].second->SetFillColor(autreColors[i]);
_autreHists[i].second->SetFillStyle(1001);
hstack->Add(_autreHists[i].second);
}
hstack->Draw("GOFF");
if(_prelim) hstack->SetTitle("CMS preliminary");
else hstack->SetTitle("CMS, #sqrt{s} = 7 TeV");
Float_t theMax = hstack->GetMaximum();
Float_t theMin = hstack->GetMinimum();
if (_hist[iHWW]) {
if (_hist[iHWW]->GetMaximum() > theMax) theMax = _hist[iHWW]->GetMaximum();
if (_hist[iHWW]->GetMinimum() < theMin) theMin = _hist[iHWW]->GetMinimum();
}
if (_data) {
Float_t dataMax = GetMaximumIncludingErrors(_data);
if (dataMax > theMax) theMax = dataMax;
}
int sampCount = GetSampCount();
float scaleBy = 1.35 + 0.2*(sampCount>6) + 0.2*(sampCount>10) + 0.2*(sampCount>14);
// Min --- only need to change if log
theMin = theMin==0?0.1:theMin/10;
if(isLog) hstack->SetMinimum(theMin);
// Max
if (_myMax != -1) {
hstack->SetMaximum(_myMax);
} else if (isLog) {
hstack->SetMaximum(pow(10,(log(theMax)/log(10)-log(theMin)/log(10)+1)*scaleBy+log(theMin)/log(10)-1));
} else {
hstack->SetMaximum(scaleBy * theMax);
}
if(_breakdown) {
THStackAxisFonts(hstack, "y", "entries");
hstack->GetHistogram()->LabelsOption("v");
} else {
THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data()));
THStackAxisFonts(hstack, "y", TString::Format("entries / %.1f %s", binWidth,_units.Data()));
if(_units.Sizeof() == 1) {
THStackAxisFonts(hstack, "x", _xLabel.Data());
// THStackAxisFonts(hstack, "y", "entries");
}
}
return hstack;
}