本文整理汇总了C++中TH1::Draw方法的典型用法代码示例。如果您正苦于以下问题:C++ TH1::Draw方法的具体用法?C++ TH1::Draw怎么用?C++ TH1::Draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TH1
的用法示例。
在下文中一共展示了TH1::Draw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PlotOnCanvas
// Draw pT balance plots
void PlotOnCanvas(TH1& genHist, TH1& recoHist, TString plotname) {
gROOT->ProcessLine(".L mystyle.C");
setTDRStyle();
tdrStyle->SetErrorX(0.5);
tdrStyle->SetPadLeftMargin(0.14);
tdrStyle->SetPadRightMargin(0.10);
tdrStyle->SetLegendBorderSize(0);
tdrStyle->SetTitleYOffset(1.5);
TCanvas canvas("canvas", "", 500, 500);
gStyle->SetOptStat(0);
genHist.SetMinimum(0);
genHist.Draw();
genHist.Draw("hist same");
recoHist.Draw("same");
recoHist.Draw("HIST same");
leg_hist = new TLegend(0.6,0.7,0.89,0.89);
leg_hist->AddEntry(&genHist,"Generator level","l");
leg_hist->AddEntry(&recoHist,"Calorimeter level","l");
leg_hist->SetFillColor(0);
leg_hist->Draw();
canvas.SaveAs(plotname+TString(".eps"));
canvas.SaveAs(plotname+TString(".gif"));
canvas.SaveAs(plotname+TString(".root"));
canvas.Close();
// delete leg_hist;
}
示例2: plotComparison
void plotComparison(TFile **input, const string &title, const bool &reverse_order = false)
{
TH1 *qcd = merge("htlep", input, 0, QCD_CHANNELS);
TH1 *ttjets = get("htlep", input[TTJETS], TTJETS);
TH1 *zjets = get("htlep", input[ZJETS], ZJETS);
TH1 *wjets = get("htlep", input[WJETS], WJETS);
TH1 *data = merge("htlep", input, RERECO, RERECO + DATA_CHANNELS);
data->SetFillColor(0);
THStack *stack = new THStack();
stack->Add(qcd);
stack->Add(ttjets);
stack->Add(zjets);
stack->Add(wjets);
if (reverse_order)
{
stack->Draw("h");
data->Draw("h same");
}
else
{
data->Draw("h");
stack->Draw("h same");
}
TLegend *legend = createLegend(title.c_str());
legend->Draw();
}
示例3: makeplotTwo
void makeplotTwo(TH1& hist1, TH1& hist2, const char* plotname, int logy) {
hist1.SetLineColor(4);
hist1.SetMarkerColor(4);
gStyle->SetOptStat(0);
TCanvas* can = new TCanvas( plotname, plotname, 500, 500);
hist1.Draw( );
hist2.Draw( "same" );
TLegend *leg = new TLegend(0.55,0.8,0.89,0.92);
leg->AddEntry( &hist1,"Reconstructed","LP");
leg->AddEntry( &hist2,"Generated","L");
leg->SetFillColor(0);
leg->SetLineColor(0);
leg->Draw();
can->SetLogy( logy );
if(logy==2) hist1.GetYaxis()->SetMoreLogLabels();
std::string plot(cmEnergy);
plot.append(plotname);
can->SaveAs( (plot+".eps").c_str() );
can->SaveAs( (plot+".gif").c_str() );
can->SaveAs( (plot+".root").c_str() );
// delete can;
cout << hist1.Integral() << endl;
}
示例4: makeplotThree
void makeplotThree(TH1& hist1, TH1& hist2, TH1& hist3, const char* plotname, int log) {
hist1.SetLineColor(4);
hist1.SetMarkerColor(4);
hist3.SetLineColor(2);
hist3.SetMarkerColor(2);
gStyle->SetOptStat(0);
TCanvas* can = new TCanvas( plotname, plotname, 500, 500);
hist1.Draw( );
hist2.Draw( "same" );
hist3.Draw( "same" );
TLegend *leg = new TLegend(0.48,0.7,0.89,0.92);
leg->AddEntry( &hist1,"CaloJet","LP");
leg->AddEntry( &hist3,"PF Jet","LP");
leg->AddEntry( &hist2,"GenJet","L");
leg->SetFillColor(0);
leg->SetLineColor(0);
leg->Draw();
can->SetLogy( log );
if(log==2) {
can->SetLogy( 1 );
hist1.GetYaxis()->SetMoreLogLabels();
}
std::string plot("ratio-");
plot.append(plotname);
can->SaveAs( (plot+".eps").c_str() );
can->SaveAs( (plot+".gif").c_str() );
can->SaveAs( (plot+".root").c_str() );
// delete can;
cout << hist1.Integral() << endl;
}
示例5: dominik
void dominik()
{
TH1* matHistogramRoman = static_cast<TH1*>(extractObjectFromFile("lyRoman.root", "lightYieldProjectionY")->At(0));
TList* objects = extractObjectFromFile("c.root", "chargeBins");
TH1* matHistogramDominik = new TH1D("matHistogramDominik", ";channel;light yield / pixels", 512, -0.5, 512-0.5);
int sipmIt = 0;
for (int i = 0; i < objects->GetSize(); ++i) {
TH1* h = static_cast<TH1*>(objects->At(i));
if (h->GetLineColor() == 8) {
for (int bin = 1; bin <= 128; ++bin) {
matHistogramDominik->SetBinContent(512 - (sipmIt * 128 + bin - 1), h->GetBinContent(bin));
if (h->GetBinError(bin) > 0)
matHistogramDominik->SetBinError(512 - (sipmIt * 128 + bin - 1), h->GetBinError(bin));
}
++sipmIt;
}
}
TCanvas* c = new TCanvas;
c->Divide(1, 2);
c->cd(1);
matHistogramDominik->Draw();
matHistogramRoman->Draw("SAME");
c->cd(2);
TH1* h = static_cast<TH1*>(matHistogramDominik->Clone());
h->Add(matHistogramRoman, -1);
h->Draw();
}
示例6: PlotOnCanvas
// Draw pT balance plots
void PlotOnCanvas(TH1& genHist, TH1& recoHist, TString plotname) {
TLine* line1 = new TLine(1.0, genHist.GetMinimum(),
1.0, genHist.GetMaximum());
line1->SetLineColor(4);
line1->SetLineWidth(2);
TCanvas canvas("canvas", "", 880, 600);
gStyle->SetOptStat(0);
genHist.Draw("hist");
line1->Draw();
recoHist.Draw("same");
recoHist.Draw("HIST same");
leg_hist = new TLegend(0.6,0.65,0.85,0.85);
leg_hist->AddEntry(&genHist,"Generator level","l");
leg_hist->AddEntry(&recoHist,"Calorimeter level","l");
leg_hist->SetFillColor(0);
leg_hist->Draw();
canvas.SaveAs(plotname+TString(".eps"));
canvas.SaveAs(plotname+TString(".gif"));
canvas.SaveAs(plotname+TString(".root"));
delete line1;
delete leg_hist;
}
示例7: MakeNsignalEff_pt15
void MakeNsignalEff_pt15(){
setTDRStyle();
gStyle->SetPalette(1);
TH1* medium = makehist("PreSelection_medium_pt15");
TH1* tight = makehist("PreSelection_tight_pt15");
TH1* tight_dxy10= makehist("PreSelection_iso_10_10_pt15");
TH1* tight_anal = makehist("PreSelection_pt15");
TLegend* legendH = new TLegend(0.6, 0.7, 0.9, 0.9);
legendH->SetFillColor(kWhite);
legendH->SetTextSize(0.03);
medium->GetXaxis()->SetTitle("m_{N} GeV");
medium->GetYaxis()->SetTitle("ID efficiency");
medium->SetMarkerColor(kRed);
tight->SetMarkerColor(kRed);
tight_dxy10->SetMarkerColor(kRed);
tight_anal->SetMarkerColor(kRed);
medium->SetMarkerStyle(20.);
tight->SetMarkerStyle(21.);
tight_dxy10->SetMarkerStyle(22.);
tight_anal->SetMarkerStyle(23.);
legendH->AddEntry(medium, "medium ID", "p");
legendH->AddEntry(tight, "tight ID", "p");
legendH->AddEntry(tight_dxy10, "tight+ dxy ", "p");
legendH->AddEntry(tight_anal, "tight+ dxy+ iso ", "p");
medium->Draw("p");
tight->Draw("psame");
tight_dxy10->Draw("psame");
tight_anal->Draw("psame");
legendH->Draw();
TGraphAsymmErrors * g = new TGraphAsymmErrors(heff);
g->SetLineWidth(2.0);
g->SetMarkerSize(2.);
// g->Draw( "9pXsame" );
CMS_lumi( c1, 2, 11 );
c1->Update();
c1->RedrawAxis();
c1->SaveAs(("/home/jalmond/WebPlots/PreApproval/SignalPlots/SignalEff_presel_med_tight_pt15.pdf" ));
}
示例8: QAvertex
void QAvertex(const Char_t *fdata, const Char_t *fmc)
{
style();
TFile *fdtin = TFile::Open(fdata);
TList *ldtin = (TList *)fdtin->Get("clist");
TH2 *hdtin = (TH2 *)ldtin->FindObject("zv");
TH1 *hdt = (TH1 *)ldtin->FindObject("zvNoSel");
SetHistoStyle(hdt, 20, kRed+1);
hdt->Scale(1. / hdt->Integral());
TH1 *hdt0010 = hdtin->ProjectionX("hdt0010", 1, 4);
SetHistoStyle(hdt0010, 20, kRed+1);
hdt0010->Scale(1. / hdt0010->Integral());
TH1 *hdt7080 = hdtin->ProjectionX("hdt7080", 11, 11);
SetHistoStyle(hdt7080, 25, kAzure-3);
hdt7080->Scale(1. / hdt7080->Integral());
TFile *fmcin = TFile::Open(fmc);
TList *lmcin = (TList *)fmcin->Get("clist");
TH1 *hmc = (TH1 *)lmcin->FindObject("zvNoSel");
SetHistoStyle(hmc, 25, kAzure-3);
hmc->Scale(1. / hmc->Integral());
TCanvas *c = new TCanvas("cVertex", "cVertex", 800, 800);
TH1 * hfr = c->DrawFrame(-20., 0., 20., 0.1);
hfr->SetTitle(";#it{z}_{vtx};");
hdt0010->Draw("same");
hdt7080->Draw("same");
TLegend *legend = new TLegend(0.20, 0.18+0.60, 0.50, 0.30+0.60);
legend->SetFillColor(0);
legend->SetBorderSize(0);
legend->SetTextFont(42);
legend->SetTextSize(0.04);
legend->AddEntry(hdt0010, "0-10%", "p");
legend->AddEntry(hdt7080, "70-80%", "p");
legend->Draw("same");
c->SaveAs(canvasPrefix+"vertex.pdf");
TCanvas *c1 = new TCanvas("cVertexDataMC", "cVertexDataMC", 800, 800);
hfr = c1->DrawFrame(-20., 0., 20., 0.1);
hfr->SetTitle(";#it{z}_{vtx};");
hdt->Draw("same");
hmc->Draw("same");
legend = new TLegend(0.20, 0.18+0.60, 0.50, 0.30+0.60);
legend->SetFillColor(0);
legend->SetBorderSize(0);
legend->SetTextFont(42);
legend->SetTextSize(0.04);
legend->AddEntry(hdt, "data", "p");
legend->AddEntry(hmc, "Monte Carlo", "p");
legend->Draw("same");
c1->SaveAs(canvasPrefix+"vertexDataMC.pdf");
//return 0;
}
示例9: Fit511Photopeak
double Fit511Photopeak(TH1* h, double* error=0)
{
TSpectrum spec(1);
spec.Search(h);
h->GetXaxis()->SetTitle("Energy [photoelectrons]");
h->Draw("e");
TH1* bg = spec.Background(h);
TH1* sig = (TH1*)(h->Clone());
sig->SetLineColor(kGreen);
sig->Add(bg,-1);
sig->Draw("same e");
sig->Fit("gaus","m","same e");
TF1* gaus = sig->GetFunction("gaus");
if(gaus)
gaus->SetLineColor(kGreen);
bg->SetLineColor(kRed);
bg->Draw("same e");
TLine* line = new TLine(gaus->GetParameter(1),0,
gaus->GetParameter(1),h->GetMaximum());
line->SetLineColor(kBlue);
line->SetLineWidth(2);
line->Draw();
double yield = spec.GetPositionX()[0]/epeak;
double err = 0;
cout<<"Results from TSpectrum: \n\t"
<<"Peak = "<<spec.GetPositionX()[0]<<" p.e.; Light Yield = "
<<yield<<" p.e./keV"<<endl;
if(gaus){
yield = gaus->GetParameter(1)/epeak;
err = gaus->GetParError(1)/epeak;
cout<<"Results from BG Subtracted Gaus Fit: \n\t"
<<"Peak = "<<gaus->GetParameter(1)<<" p.e.; Light Yield = "
<<yield<<" +/- "<<err<<" p.e./keV"<<endl;
err = max(err, TMath::Abs(yield-spec.GetPositionX()[0]/epeak));
}
TLegend* leg = new TLegend(.6,.6,.9,.9);
leg->AddEntry(h,"Raw Spectrum","lpe");
leg->AddEntry(bg,"Background","lpe");
leg->AddEntry(sig,"Signal","lpe");
char title[20];
sprintf(title,"Yield = %.2f pe/keV",yield);
leg->AddEntry(line, title ,"l");
leg->Draw();
if(error) *error = err;
return yield;
}
示例10: draw_output_stat
void plotter::draw_output_stat(TH1* output_, TH1* stat_, TH1D* truth_, bool norm, TString file_name){
// std::vector<double> sys = get_sys_errors();
// TH1* output_sys = add_error_bar(output, sys);
TH1* output = (TH1*) output_->Clone("output");
TH1* stat = (TH1*) stat_->Clone("stat");
TH1D* truth = (TH1D*) truth_->Clone("truth");
TCanvas *c = new TCanvas("c","",600,600);
double ymax;
gPad->SetLeftMargin(0.15);
if(truth->GetMaximum() > output->GetMaximum()) ymax = 1.5 * truth->GetMaximum();
else ymax = 1.5 * output->GetMaximum();
TGaxis::SetMaxDigits(3);
output->SetTitle(" ");
output->GetYaxis()->SetRangeUser(0., ymax);
output->GetXaxis()->SetTitle("Leading-jet mass [GeV]");
if(norm) output->GetYaxis()->SetTitle("#frac{1}{#sigma} #frac{d#sigma}{dm_{jet}} [#frac{1}{GeV}]");
else output->GetYaxis()->SetTitle("events");
output->GetYaxis()->SetTitleOffset(1.1);
output->GetXaxis()->SetTitleOffset(0.9);
output->GetYaxis()->SetTitleSize(0.05);
output->GetXaxis()->SetTitleSize(0.05);
output->GetYaxis()->SetNdivisions(505);
output->SetLineColor(kBlack);
output->SetMarkerColor(kBlack);
output->SetMarkerStyle(8);
output->SetMarkerSize(1);
output->Draw("E1");
stat->SetLineColor(kBlack);
stat->SetMarkerColor(kBlack);
stat->SetMarkerStyle(8);
stat->SetMarkerSize(1);
gStyle->SetEndErrorSize(5);
truth->SetLineWidth(3);
truth->SetLineColor(kRed);
truth->SetLineStyle(2);
truth->Draw("HIST SAME");
stat->Draw("E1 SAME");
output->Draw("E1 SAME");
TLegend *l=new TLegend(0.5,0.65,0.85,0.85);
l->SetBorderSize(0);
l->SetFillStyle(0);
l->AddEntry(output,"data unfolded","pl");
l->AddEntry(truth,"MC particle level","pl");
l->SetTextSize(0.04);
l->Draw();
c->SaveAs(directory + file_name + ".pdf");
delete c;
}
示例11: plotCut2DSignal
void plotCut2DSignal()
{
string canvas_title = "Cut 2D Signal";
TCanvas *canvas = new TCanvas(canvas_title.c_str(), canvas_title.c_str());
canvas->SetWindowSize(1200, 640);
canvas->Divide(3, 2);
canvas_title = "DeltaR Signal";
TCanvas *canvas_dr = new TCanvas(canvas_title.c_str(), canvas_title.c_str());
canvas_dr->SetWindowSize(1200, 640);
canvas_dr->Divide(3, 2);
canvas_title = "pTrel Signal";
TCanvas *canvas_ptrel = new TCanvas(canvas_title.c_str(), canvas_title.c_str());
canvas_ptrel->SetWindowSize(1200, 640);
canvas_ptrel->Divide(3, 2);
for(int i = 0; SIGNAL_CHANNELS > i; ++i)
{
int id = BACKGROUND_CHANNELS + i;
TH1 *hist = get("dr_vs_ptrel", input_s1[id], id);
if (!hist)
continue;
canvas->cd(i + 1);
style(hist, id);
hist->SetMarkerSize(0.1);
hist->Draw("scat");
TLegend *legend = createLegend(toString(id));
legend->Draw();
canvas_ptrel->cd(i + 1);
TH2 *hist2d = dynamic_cast<TH2 *>(hist);
TH1 *ptrel = dynamic_cast<TH1 *>(hist2d->ProjectionX()->Clone());
style(ptrel, id);
ptrel->Draw();
legend->Draw();
canvas_dr->cd(i + 1);
TH2 *hist2d = dynamic_cast<TH2 *>(hist);
TH1 *dr = dynamic_cast<TH1 *>(hist2d->ProjectionY()->Clone());
style(dr, id);
dr->Draw();
legend->Draw();
}
}
示例12: QAcentrality
void QAcentrality(const Char_t *fdata)
{
style();
TFile *fin = TFile::Open(fdata);
TList *lin = (TList *)fin->Get("clist");
lin->ls();
TH1 *hin = (TH1 *)lin->FindObject("EvCentrDist");
Float_t sum = 1.2 * hin->Integral(hin->FindBin(0.1), hin->FindBin(79.9));
hin->Scale(1. / sum);
SetHistoStyle(hin, 20, kRed+1);
TCanvas *c = new TCanvas("cQAcentrality", "cQAcentrality", 800, 800);
TH1 * hfr = c->DrawFrame(0., 0.005, 100., 0.015);
hfr->SetTitle(";centrality percentile;events");
hin->Draw("same");
c->SaveAs(canvasPrefix+"centrality.pdf");
TH2 *hinv0 = (TH2 *)lin->FindObject("V0");
TCanvas *cv0 = new TCanvas("cQAcentralityV0", "cQAcentralityV0", 800, 800);
cv0->SetLogx();
cv0->SetLogz();
// TH1 * hfrv0 = cv0->DrawFrame(100., -0.5, 50000., 10.5);
// DrawBinLabelsY(hfrv0, kTRUE);
// hfrv0->SetTitle(";V0 signal;");
//hinv0->Draw("same,col");
hinv0->Draw("col");
cv0->SaveAs(canvasPrefix+"centralityV0.pdf");
}
示例13: makeplots1D
// Make 1D comparison plots
void makeplots1D( TH1& eff, TH1& base, TH1& destination, TString name) {
gROOT->ProcessLine(".L ~/tdrstyle.C");
setTDRStyle();
TGraphAsymmErrors *g1 = new TGraphAsymmErrors();
g1->BayesDivide(&destination, &base, "");
g1->GetYaxis()->SetRangeUser(0.5, 1.05);
eff.SetLineColor(2);
eff.SetMarkerStyle(22);
eff.SetMarkerSize(1.4);
eff.SetMarkerColor(2);
//
g1->GetYaxis()->SetTitle("Efficiency");
if(name.Contains("_Eta"))
g1->GetXaxis()->SetTitle("#eta");
if(name.Contains("_Phi"))
g1->GetXaxis()->SetTitle("#phi");
if(name.Contains("_Pt"))
g1->GetXaxis()->SetTitle("p_{T} (GeV/c)");
TCanvas canvas("canvas",name,600,600);
g1->Draw("APE");
eff.Draw("same");
canvas.SaveAs(name + TString(".eps"));
canvas.SaveAs(name + TString(".gif"));
canvas.Close();
delete g1;
}
示例14: DrawNext
// draw the next waveform that we find associated with an event
void DrawNext(void)
{
static Int_t evno=0;
if (tree == nullptr) {
tree = (TTree*)gROOT->FindObject("FragmentTree");
}
tree->SetBranchAddress("TFragment", &frag);
do {
tree->GetEntry(evno++);
} while (frag->wavebuffer.empty());
cout<<"Event number "<<evno<<endl;
frag->Print();
//printf("wavebuffer.size() = %i\n",wavebuffer.size());
TH1 *his = makeHisto(frag->wavebuffer);
TChannel *chan = TChannel::GetChannel(frag->ChannelAddress);
// if(chan && (strncmp(chan->GetChannelName(),"DSC",3)==0))
// TH1 *his = makeDescantHisto(frag->wavebuffer);
if(chan)
his->SetTitle(chan->GetChannelName());
his->Draw();
}
示例15: fadc_fit_heights
void fadc_fit_heights(std::string fadc_id,std::string hist_type)
{
/*****************************************************************/
// Prepare the canvas
gStyle->SetOptFit(1111);
TCanvas *AlCapCanvas = (TCanvas *) gROOT->GetListOfCanvases()->At(0);
AlCapCanvas->Clear();
AlCapCanvas->Divide(4,2);
// gROOT->ProcessLine(".L common/get_histogram.C"); // get_histogram() is called here
/*****************************************************************/
const int n_channels = 8;
std::string bank_names[n_channels] = {"Na", "Nb", "Nc", "Nd", "Ne", "Nf", "Ng", "Nh"};
std::string name;
double mean = 0;
double rms = 0;
for (int iChn = 0; iChn < n_channels; iChn++) {
name=bank_names[iChn]+fadc_id;
TH1* hist = get_histogram(name, hist_type);
mean = hist->GetMean();
rms = hist->GetRMS();
AlCapCanvas->cd(iChn+1);
if (hist->Integral()!=0) {
TF1* gaus = new TF1("gaus","gaus",mean-rms,mean+rms);
hist->Fit("gaus","Q");
hist->GetXaxis()->SetRange(mean-2*rms,mean+2*rms);
hist->Draw();
}
}
}