当前位置: 首页>>代码示例>>C++>>正文


C++ TLegend::GetListOfPrimitives方法代码示例

本文整理汇总了C++中TLegend::GetListOfPrimitives方法的典型用法代码示例。如果您正苦于以下问题:C++ TLegend::GetListOfPrimitives方法的具体用法?C++ TLegend::GetListOfPrimitives怎么用?C++ TLegend::GetListOfPrimitives使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TLegend的用法示例。


在下文中一共展示了TLegend::GetListOfPrimitives方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: AddLegend

//_____________________________________________________
TLegend* GFHistManager::AddLegend(Int_t layer, Int_t histoNum, 
				  const char* header, Bool_t referAll)
{
  // adds a legend referencing all hists in same pad 'histoNum' of layer
  // 

  // FIXME: use help of other AddLegend method?
  if(!this->CheckHistNum("AddLegend", layer, histoNum)) return NULL;

  TObjArray* legendsOfLayer = this->MakeLegends(layer);
  TLegend* legend = (legendsOfLayer->GetSize() <= histoNum ? 
		     NULL : static_cast<TLegend*>(legendsOfLayer->At(histoNum)));
  if(!legend) {
    legend = new TLegend(fLegendX1, fLegendY1, fLegendX2, fLegendY2);
#if ROOT_VERSION_CODE < ROOT_VERSION(5,6,0)
    if (TString(gStyle->GetName()) == "Plain") legend->SetBorderSize(1);
#endif
    legendsOfLayer->AddAtAndExpand(legend, histoNum);
  }

  if(header) legend->SetHeader(header);
  GFHistArray* hists = this->GetHistsOf(layer, histoNum);
  TList* legendEntries = legend->GetListOfPrimitives();

  if(referAll){
    TIter histsIter(hists);
    while(TObject* hist = histsIter.Next()){
      Bool_t addNew = kTRUE;
      TIter legEntrIter(legendEntries);
      while(TLegendEntry* entry = static_cast<TLegendEntry*>(legEntrIter())){
	if(hist == entry->GetObject()) {addNew = kFALSE; break;}
      }  
      if(addNew) legend->AddEntry(hist, hist->GetName(), fgLegendEntryOption);
    }
  }

  if(layer < fCanArrays->GetEntriesFast()) {
    this->Update(layer); // if canvas already drawn
  }
  return legend;
}
开发者ID:12345ieee,项目名称:cmg-cmssw,代码行数:42,代码来源:GFHistManager.C

示例2: Combine_HTBin


//.........这里部分代码省略.........
       // ================================================================================================
       Cuts[i] = ((TH1*)(Stack[0]->GetStack()->Last()))->GetEntries();
       //cout << "Entries: " << Cuts[i] << endl; 


       gStyle->SetOptStat(0); 
       gStyle->SetOptTitle(0);
       gStyle->SetLegendBorderSize(0); 


       // Plot Parameters
       leg = new TLegend(0.50,0.35,0.8,0.8);
       leg->SetHeader("#splitline{#sqrt{s} = 100 TeV, #int L dt = 1 fb^{-1}}{W^{#pm}/Z^{0} + Jets}");
       //leg->SetHeader("#sqrt{s} = 100 TeV, #int L dt = 10 pb^{-1}");
       leg->AddEntry(HistPlot[0][0] ," ","");
       leg->AddEntry(HistPlot[0][0] ," ","");
       leg->AddEntry(HistPlot[0][0] ,"HTBin 50#rightarrow100     ","f");
       leg->AddEntry(HistPlot[1][0] ,"HTBin 100#rightarrow200    ","f");
       leg->AddEntry(HistPlot[2][0] ,"HTBin 200#rightarrow400    ","f");
       leg->AddEntry(HistPlot[3][0] ,"HTBin 400#rightarrow600    ","f");
       leg->AddEntry(HistPlot[4][0] ,"HTBin 600#rightarrow800    ","f");
       leg->AddEntry(HistPlot[5][0] ,"HTBin 800#rightarrow1000   ","f");
       leg->AddEntry(HistPlot[6][0] ,"HTBin 1000#rightarrow1500  ","f");
       leg->AddEntry(HistPlot[7][0] ,"HTBin 1500#rightarrow2000  ","f");
       leg->AddEntry(HistPlot[8][0] ,"HTBin 2000#rightarrow2500  ","f");
       leg->AddEntry(HistPlot[9][0] ,"HTBin 2500#rightarrow3000  ","f");
       leg->AddEntry(HistPlot[10][0],"HTBin 3000#rightarrow4000  ","f");
       leg->AddEntry(HistPlot[11][0],"HTBin 4000#rightarrow5000  ","f");
       leg->AddEntry(HistPlot[12][0],"HTBin 5000#rightarrow10000 ","f");
       leg->AddEntry(HistPlot[13][0],"HTBin 10000#rightarrow15000","f");
       leg->AddEntry(HistPlot[14][0],"HTBin 15000#rightarrow20000","f");
       leg->AddEntry(HistPlot[15][0],"HTBin 20000#rightarrow25000","f");
       //leg->SetFillColorAlpha(0,0);
       TLegendEntry *header = (TLegendEntry*)leg->GetListOfPrimitives()->First();
       //header->SetTextAlign(22);
       //header->SetTextColor(2);
       header->SetTextSize(0.03);

       //Draw an axis on the right side
       //TGaxis *A1 = new TGaxis(0,5e9,6000,5e9,"",510,"-");


       // MET

       can[0]->cd();
       Stack[0]->Draw();
       Stack[0]->GetXaxis()->SetTitle("E^{Miss}_{T} [GeV]");
       Stack[0]->GetYaxis()->SetTitle("Events/100 GeV");
       Stack[0]->GetYaxis()->SetTitleOffset(1.25);
       Stack[0]->GetXaxis()->SetRangeUser(0,6000);
       Stack[0]->SetMinimum(0.3);
       Stack[0]->SetMaximum(10e8);
       Stack[0]->Draw();
       leg->Draw("same");
 
       // Jet1 Pt
       can[1]->cd();
       Stack[1]->Draw();
       Stack[1]->GetXaxis()->SetTitle("P_{T} Jet_{1} [GeV/c]");
       Stack[1]->GetYaxis()->SetTitle("Events/100 GeV");
       Stack[1]->GetYaxis()->SetTitleOffset(1.25);
       Stack[1]->GetXaxis()->SetRangeUser(0,6000);
       Stack[1]->SetMinimum(0.3);
       Stack[1]->SetMaximum(10e8);
       Stack[1]->Draw();
       leg->Draw("same");
开发者ID:BlueShifTA,项目名称:FCC_Project,代码行数:67,代码来源:Combine_HTBin_wzjet.C

示例3: misalignmentDependence

void misalignmentDependence(TCanvas *c1old,
                            Int_t nFiles,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar,
                            TF1 *function,Int_t parameter,TString parametername = "",TString functionname = "",
                            Bool_t resolution = false,
                            TString saveas = "")
{
    cout << saveas << endl;
    if (c1old == 0) return;
    c1old = (TCanvas*)c1old->Clone("c1old");
    if (misalignment == "" || yvar == "") return;
    Bool_t drawfits = (parameter < 0);
    if (parameter < 0)
        parameter = -parameter - 1;   //-1 --> 0, -2 --> 1, -3 --> 2, ...
    TString yaxislabel = nPart(1,parametername);
    TString parameterunits = nPart(2,parametername);
    if (parameterunits != "")
        yaxislabel.Append(" (").Append(parameterunits).Append(")");
    TList *list = c1old->GetListOfPrimitives();
    int n = list->GetEntries() - 2 - (xvar == "");

    setTDRStyle();
    gStyle->SetOptStat(0);
    gStyle->SetOptFit(0);
    gStyle->SetFitFormat("5.4g");
    gStyle->SetFuncColor(2);
    gStyle->SetFuncStyle(1);
    gStyle->SetFuncWidth(1);
    if (!drawfits)
    {
        gStyle->SetCanvasDefW(678);
        gStyle->SetPadRightMargin(0.115);
    }

    TH1 **p = new TH1*[n];
    TF1 **f = new TF1*[n];
    Bool_t used[n];
    for (Int_t i = 0; i < n; i++)
    {
        stringstream s0;
        s0 << "p" << i;
        TString pname = s0.str();
        p[i] = (TH1*)list->/*At(i+1+(xvar == ""))*/FindObject(pname);
        used[i] = (p[i] != 0);
        if (used[i])
            p[i]->SetDirectory(0);
        if (xvar == "" && function == 0)
            continue;
        stringstream s;
        s << function->GetName() << i;
        TString newname = s.str();
        f[i] = (TF1*)function->Clone(newname);
        stufftodelete->Add(f[i]);
    }

    Double_t *result = new Double_t[nFiles];
    Double_t *error  = new Double_t[nFiles];
    if (xvar == "" && function == 0)
    {
        yaxislabel = axislabel(yvar,'y',resolution);
        for (Int_t i = 0; i < nFiles; i++)
        {
            if (!used[i]) continue;
            if (!resolution)
            {
                result[i] = p[i]->GetMean();
                error[i]  = p[i]->GetMeanError();
            }
            else
            {
                result[i] = p[i]->GetRMS();
                error[i]  = p[i]->GetRMSError();
            }
            cout << result[i] << " +/- " << error[i] << endl;
        }
    }
    else
    {
        for (int i = 0; i < n; i++)
        {
            if (!used[i]) continue;
            f[i]->SetLineColor(colors[i]);
            f[i]->SetLineStyle(styles[i]);
            f[i]->SetLineWidth(1);
            p[i]->SetMarkerColor(colors[i]);
            p[i]->SetMarkerStyle(20+i);
            p[i]->SetLineColor(colors[i]);
            p[i]->SetLineStyle(styles[i]);
            p[i]->Fit(f[i],"IM");
            error[i]  = f[i]->GetParError (parameter);
            if (function->GetName() == TString("sine"))
            {
                if (f[i]->GetParameter(0) < 0)
                {
                    f[i]->SetParameter(0,-f[i]->GetParameter(0));
                    f[i]->SetParameter(2,f[i]->GetParameter(2)+pi);
                }
                while(f[i]->GetParameter(2) >= 2*pi)
                    f[i]->SetParameter(2,f[i]->GetParameter(2)-2*pi);
                while(f[i]->GetParameter(2) < 0)
                    f[i]->SetParameter(2,f[i]->GetParameter(2)+2*pi);
//.........这里部分代码省略.........
开发者ID:hroskes,项目名称:HiggsPlot,代码行数:101,代码来源:misalignmentDependence.C

示例4: drawpdgstack

  void drawpdgstack(std::string const & which_pdg,
		    std::string const & cname,
		    std::string const & dr,
		    std::string const & binning,
		    std::string const & we = "",
		    std::string const & op = "",
		    std::string const & title = "",
		    std::string const & xtitle = "",
		    std::string const & ytitle = "",
		    bool const pdg_sign = true) {

    ofile->cd();
    
    TH1F * hist = getpdgs(which_pdg.c_str(), we);
    if(!hist) {
      std::cout << "drawpdgstack: Empty pdg hist for \"" << which_pdg << "\" with selection \"" << we << "\"\n";
      return;
    }    

    THStack * stack = new THStack("stack", "");
    TLegend * legend = new TLegend(0.6, 0.9, 0.9, 0.6);

    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);
//.........这里部分代码省略.........
开发者ID:rmurrells,项目名称:VertexBuilderTest,代码行数:101,代码来源:plot.cpp

示例5: if


//.........这里部分代码省略.........
        for (Int_t i = 1; i < n && allthesame; i++)
        {
            if (lengths[i] != lengths[0])
                allthesame = false;
        }
        if (!allthesame && xvar != "runNumber")
            for (Int_t i = 0; i < n; i++)
            {
                p[i]->Scale(1.0/lengths[i]);
            }
        maxp = (TH1F*)p[0]->Clone("maxp");
        maxp->SetLineColor(kWhite);
        for (Int_t i = 1; i <= maxp->GetNbinsX(); i++)
        {
            for (Int_t j = 0; j < n; j++)
            {
                if (files[j].Contains("MC") && xvar == "runNumber")
                    continue;
                maxp->SetBinContent(i,TMath::Max(maxp->GetBinContent(i),p[j]->GetBinContent(i)));
            }
        }
        maxp->Draw();
        p[0]->Draw("same");
    }
    TLegend *legend = new TLegend(.6,.7,.9,.9,"","br");
    if (n == 1 && files[0].Contains("MC") && xvar == "runNumber")
    {
        placeholder(saveas,yvar == "");
        return 0;
    }
    if (n>=2)
    {
        if (!(files[0].Contains("MC") && xvar == "runNumber") && files[0] != "")
        {
            if (type == Resolution || type == Profile)
                legend->AddEntry(p[0],names[0],"pl");
            else if (type == Histogram || type == OrgHistogram)
            {
                legend->AddEntry(p[0],names[0],"l");
                legend->AddEntry((TObject*)0,meansrmss[0],"");
            }
        }
        for (Int_t i = 1; i < n; i++)
        {
            if (files[i].Contains("MC") && xvar == "runNumber")
                continue;
            if (type == Resolution || type == Profile)
            {
                p[i]->Draw("same P");
                legend->AddEntry(p[i],names[i],"pl");
            }
            else if (type == Histogram || type == OrgHistogram)
            {
                p[i]->Draw("same");
                legend->AddEntry(p[i],names[i],"l");
                legend->AddEntry((TObject*)0,meansrmss[i],"");
            }
        }

        if (legend->GetListOfPrimitives()->At(0) == 0)
        {
            delete legend;
            placeholder(saveas,yvar == "");
            return 0;
        }

        
        c1->Update();
        Double_t x1min  = .98*gPad->GetUxmin() + .02*gPad->GetUxmax();
        Double_t x2max  = .02*gPad->GetUxmin() + .98*gPad->GetUxmax();
        Double_t y1min  = .98*gPad->GetUymin() + .02*gPad->GetUymax();
        Double_t y2max  = .02*gPad->GetUymin() + .98*gPad->GetUymax();
        Double_t width  = .4*(x2max-x1min);
        Double_t height = (1./20)*legend->GetListOfPrimitives()->GetEntries()*(y2max-y1min);
        if (type == Histogram || type == OrgHistogram)
        {
            width *= 2;
            height /= 2;
            legend->SetNColumns(2);
        }
        Double_t newy2max = placeLegend(legend,width,height,x1min,y1min,x2max,y2max);
        maxp->GetYaxis()->SetRangeUser(gPad->GetUymin(),(newy2max-.02*gPad->GetUymin())/.98);
                
        legend->SetFillStyle(0);
        legend->Draw();
    }
    if (saveas != "")
    {
        saveplot(c1,saveas);
        for (int i = 0; i < n; i++)
        {
            //delete p[i];
            //delete g[i];
        }
        //delete list;
        //delete maxp;
        //delete legend;
    }
    return c1;
}
开发者ID:awhitbeck,项目名称:usercode-JHU,代码行数:101,代码来源:trackSplitPlot.C


注:本文中的TLegend::GetListOfPrimitives方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。