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


C++ TCanvas::BuildLegend方法代码示例

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


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

示例1: checkPullTree


//.........这里部分代码省略.........
    hTempSigma->SetMarkerColor(kMagenta);
    hTempSigma->SetLineWidth(2);
    TH1D* hTempChi2 = (TH1D*)gDirectory->Get(Form("%s_chi2", hTemp->GetName()));
    hTempChi2->SetTitle(Form("#chi^{2} / NDF (pull), %s", thetaString.Data()));
    hTempChi2->GetXaxis()->SetMoreLogLabels(kTRUE);
    hTempChi2->SetLineColor(kMagenta + 2);
    hTempChi2->SetMarkerStyle(20);
    hTempChi2->SetMarkerColor(kMagenta + 2);
    hTempChi2->SetLineWidth(2);

    hTemp->DrawCopy("colz");
    hTempMean->DrawCopy("same");
    hTempSigma->DrawCopy("same");
    hTempChi2->Scale(-1./10.);
    hTempChi2->DrawCopy("same");
    hTempChi2->Scale(-10.);

    canvPullMean->cd();
    hTempMean->SetLineColor(1 + ((j >= 9) ? (39 + 2 * (j - 9)) : j));
    hTempMean->SetMarkerColor(1 + ((j >= 9) ? (39 + 2 * (j - 9)) : j));
    hTempMean->DrawCopy((i == 0 ? "" : "same"));

    canvPullSigma->cd();
    hTempSigma->SetLineColor(1 + ((j >= 9) ? (39 + 2 * (j - 9)) : j));
    hTempSigma->SetMarkerColor(1 + ((j >= 9) ? (39 + 2 * (j - 9)) : j));
    hTempSigma->DrawCopy((i == 0 ? "" : "same"));

    canvPullChi2->cd();
    hTempChi2->SetLineColor(1 + ((j >= 9) ? (39 + 2 * (j - 9)) : j));
    hTempChi2->SetMarkerColor(1 + ((j >= 9) ? (39 + 2 * (j - 9)) : j));
    hTempChi2->DrawCopy((i == 0 ? "" : "same"));
  }

  canvPullMean->BuildLegend();
  canvPullSigma->BuildLegend();
  canvPullChi2->BuildLegend();
*/
  // Histograms with additional correction
  TCanvas* canvPullMeanCorr = 0x0;
  TCanvas* canvPullSigmaCorr = 0x0;
  TCanvas* canvPullChi2Corr = 0x0;
  TCanvas* canvPullCorr[nThetaHistos + 1];
  for (Int_t i = 0; i < nThetaHistos + 1; i++) 
    canvPullCorr[i] = 0x0;
  
  if (hMap) {
    // Mean, Sigma, chi^2/NDF of pull of different theta bins and all in one plot
    canvPullMeanCorr = new TCanvas("canvPullMeanCorr", "canvPullMeanCorr", 100,10,1380,800);
    canvPullMeanCorr->SetLogx(kTRUE);
    canvPullMeanCorr->SetGridx(kTRUE);
    canvPullMeanCorr->SetGridy(kTRUE);
    canvPullSigmaCorr = new TCanvas("canvPullSigmaCorr", "canvPullSigmaCorr", 100,10,1380,800);
    canvPullSigmaCorr->SetLogx(kTRUE);
    canvPullSigmaCorr->SetGridx(kTRUE);
    canvPullSigmaCorr->SetGridy(kTRUE);
    canvPullChi2Corr = new TCanvas("canvPullChi2Corr", "canvPullChi2Corr", 100,10,1380,800);
    canvPullChi2Corr->SetLogx(kTRUE);
    canvPullChi2Corr->SetGridx(kTRUE);
    canvPullChi2Corr->SetGridy(kTRUE);
    
    for (Int_t i = 0, j = nThetaHistos; i < nThetaHistos + 1; i++, j--)  {
      canvPullCorr[i] = new TCanvas(Form("canvPullCorr_%d", i), "canvPullCorr", 100,10,1380,800);
      canvPullCorr[i]->cd();
      canvPullCorr[i]->SetLogx(kTRUE);
      canvPullCorr[i]->SetLogz(kTRUE);
      canvPullCorr[i]->SetGrid(kTRUE, kTRUE);
开发者ID:ktf,项目名称:AliPhysics,代码行数:67,代码来源:checkPullTree.C

示例2: makePlots


//.........这里部分代码省略.........
                  TH1F* H_bins_num;
                  TH1F* H_bins_den;
                  int id = 0;
                  for (int k = 0; k < inputXtitle.size(); k++)
                   {
                     if (hist2name == inputHistoName.at(k)){
                      id=k;
                    }
                   }
                  if (inputdifferentBinSize.at(id)==1){
                     int Nbins = h_num->GetXaxis()->GetNbins();
                     int arrayD = (int*)inputNbins.at(id);
                     float *BINS = new float [arrayD];
                     for (int b = 0; b <= arrayD; b++ )
                       {
                          if (b < (arrayD-1))
                           {
                             BINS[b] = (float)b*(h_num->GetXaxis()->GetBinWidth(b));
                           }
                          else {
                             BINS[b] = (float)inputBinSize.at(id);
                          }
                       }
                     H_bins_num = new TH1F("h_NUM", "h_NUM", inputNbinMax.at(id), BINS);
                     H_bins_den = new TH1F("h_DEN", "h_DEN", inputNbinMax.at(id), BINS);
                     for (int b = 0; b <= (Nbins+1); b++ )
                       {
                         H_bins_num->SetBinContent(b, h_num->GetBinContent(b));
                         H_bins_den->SetBinContent(b, h_den->GetBinContent(b));
                       }
                  }

                  if (inputdifferentBinSize.at(id)==1){
                     TGraphAsymmErrors* gr1 = new TGraphAsymmErrors( H_bins_num, H_bins_den, "b(1,1) mode" );
                  } else{
                    cout << "h_num "<<h_num->GetXaxis()->GetNbins() << "  h_den "<<h_den->GetXaxis()->GetNbins()<<endl;
                    cout << "h_num "<<h_num->Integral() << "  h_den "<<h_den->Integral()<<endl;
                    TGraphAsymmErrors* gr1 = new TGraphAsymmErrors( h_num, h_den, "b(1,1) mode" );
                  }
		  int setcolor = inputColor.at(j);
		  int marker   = inputMarkerStyle.at(j);
                  string processlegend = (inputLegend.at(j)).c_str();
                  gr1->SetMarkerStyle(marker);
                  gr1->SetMarkerColor(setcolor);
                  gr1->SetTitle(processlegend.c_str());
                  gr1->SetFillStyle(0);
                  mg->SetTitle(hist2name.c_str());
                  mg->Add(gr1);
		}// close if (foundHisto)
 
	      c->cd();
 	      c->SetGrid(); 
	    } // close for loop inputRootFile

          mg->Draw("APsame");
          for (int k = 0; k < inputXtitle.size(); k++)
           {
              if (hist2name == inputHistoName.at(k))
               {
                 mg->GetXaxis()->SetTitle((inputXtitle.at(k)).c_str());
                 mg->GetYaxis()->SetTitle((inputYtitle.at(k)).c_str());
                 mg->GetXaxis()->SetTitleSize(0.05);
                 mg->GetYaxis()->SetTitleSize(0.05);
                 mg->SetMaximum((float)inputYrangeMax.at(k));
               }
           }
          c->Update();
          TLegend* legend = c->BuildLegend(0.55,0.8,0.90,0.94);
          //TLegend *legend = new TLegend(0.2, 0.85-.035*inputLegend.size(), 0.5, 0.90,NULL,"brNDC");
          legend->SetTextFont(42);
          legend->SetLineColor(1);
          legend->SetLineStyle(1);
          legend->SetLineWidth(1);
          legend->SetFillColor(0);
          legend->SetFillStyle(1001);
          legend->SetBorderSize(0);
          legend->SetFillColor(kWhite);

	  TFile *hfile = (TFile*)gROOT->FindObject(HistosOutputRootFile.c_str());
	  if (hfile) {hfile->Close();}
	  hfile = new TFile(HistosOutputRootFile.c_str(),"UPDATE");

          for (int o = 0; o < inputHistoName.size(); o++)
             {
                if ( c->GetName() == inputHistoName.at(o) )
                  {
                     string save = configFilePath+"/"+inputHistoName.at(o)+".pdf";  
                     c->SaveAs(save.c_str());
                     c->Write();    
                     break;
                  }
             }

	  hfile->Close();
          c->Close();
	  
	}  // close foor loop numHistos     
      
    } // close if numHistos % inputRootFile.size() == 0
} // close  makePlots function
开发者ID:acelik,项目名称:PhysicsPlotter,代码行数:101,代码来源:EfficiencyPlotter.cpp

示例3: GraphSysErr


//.........这里部分代码省略.........
  // Set some key/value pairs 
  gse->SetKey("laboratory", "The Center");
  gse->SetKey("accelerator", "Mega Collider");
  gse->SetKey("detector", "Huge Experiment");
  gse->SetKey("author", "Christensen");
  gse->SetKey("reference","Jour.All.Things A1,999");
  gse->SetKey("doi","9999-9999-9999-9999");
  gse->SetKey("abstract", "The data");
  gse->SetKey("location", "In the paper");
  gse->SetKey("reackey", "graviton -> tachyons");
  gse->SetKey("obskey", "GUT");
  // Adding qualifiers 
  gse->AddQualifier("question", "Life, universe, and everything");
  
  // Two sources of common errors one relative, one absolue
  UInt_t cm1 = gse->DefineCommon("Common 0.05", false, .05);
  UInt_t cm2 = gse->DefineCommon("Common 10%", true, .1);
  
  // Two sources of point-to-point errors, one relative, one absolute
  UInt_t pp1 = gse->DeclarePoint2Point("Point-to-Point 0.1-0.2", true);
  UInt_t pp2 = gse->DeclarePoint2Point("Point-to-Point 5-10%", false);
  
  // Set options on summed errors (in case of option COMBINED)
  gse->SetSumLineColor(kRed+2);
  gse->SetSumLineWidth(2);
  gse->SetSumTitle("All errors");
  gse->SetSumOption(GraphSysErr::kHat);
  
  // Set attributes of common errors 
  gse->SetSysFillColor(cm1, kRed+2);
  gse->SetSysFillStyle(cm1, 3001);
  gse->SetSysLineColor(cm1, kRed+2);
  gse->SetSysFillColor(cm2, kCyan+2);
  gse->SetSysFillStyle(cm2, 3001);
  gse->SetSysOption(cm1, GraphSysErr::kBox);
  gse->SetSysOption(cm2, GraphSysErr::kRect);
  
  // Set attributes of other errors 
  gse->SetSysLineColor(pp1, kBlue+2);
  gse->SetSysLineWidth(pp1, 2);
  gse->SetSysLineColor(pp2, kGreen+2);
  gse->SetSysLineWidth(pp2, 3);
  gse->SetSysOption(pp1, GraphSysErr::kBar);
  gse->SetSysOption(pp2, GraphSysErr::kHat);
  
  // Fill a histogram with a Guassian random deviate 
  TH1* h = new TH1F("h", "h", 30, -3, 3);
  h->Sumw2();
  h->SetDirectory(0);
  h->FillRandom("gaus",1000);
  h->Scale(1./1000, "width");
  
  // Fill in the data points 
  for (Int_t i = 0; i < h->GetNbinsX(); i++) { 
    Int_t    bin = i+1;
    Double_t x   = h->GetXaxis()->GetBinCenter(bin);
    Double_t y   = h->GetBinContent(bin);
    Double_t sta = h->GetBinError(bin);
    Double_t w   = h->GetXaxis()->GetBinWidth(bin);
    
    // Set data 
    gse->SetPoint(i, x, y);
    gse->SetPointError(i, w/2, w/2);
    gse->SetStatError(i, sta);
    
    // Set point-to-point errors 
    gse->SetSysError(pp1, i, 0., gRandom->Uniform(0.1, 0.2));
    gse->SetSysError(pp2, i, 0., 0., 
		     gRandom->Uniform(0.05, 0.1),
		     gRandom->Uniform(0.05, 0.1));
  } 
  // Remove temporary histogram
  delete h;

  // Build our canvas 
  TCanvas* c = new TCanvas("c","c", 1400, 1000);
  c->SetFillColor(0);
  c->SetFillStyle(0);
  c->SetTopMargin(0.01);
  c->SetRightMargin(0.01);
  
  // Draw or fit (and draw) a Guassian to the data
  const char* option = "STACK stat axis quad split max west";
  if (!fit) 
    gse->Draw(option);
  else 
    gse->Fit("gaus", "SQ", option, -3, 3);

  // Make a legend 
  TLegend* l = c->BuildLegend(0.7,0.7,0.97,0.97);
  l->SetFillColor(0);
  l->SetFillStyle(0);
  l->SetBorderSize(0);

  // update the canvas and print
  c->Modified();
  c->Update();
  c->cd();
  c->Print("Example.png");
}
开发者ID:ktf,项目名称:AliPhysics,代码行数:101,代码来源:Example.C

示例4: Interpolate

void Interpolate(const TString& trigger="INEL")
{
  if (gSystem->Getenv("FWD"))
    fwd = gSystem->Getenv("FWD");
  else 
    fwd = gSystem->ExpandPathName("$ALICE_PHYSICS/PWGLF/FORWARD/analysis2");
  gROOT->SetMacroPath(Form("%s/dndeta:%s", gROOT->GetMacroPath(),fwd));

  if (!gROOT->GetClass("Drawer"))  gROOT->LoadMacro("Drawer.C+");

  TH1* h0900 = GetOne( 900, trigger);
  TH1* h2760 = GetOne(2760, trigger);
  TH1* h7000 = GetOne(7000, trigger);
  TH1* h8000 = GetOne(8000, trigger);
  Info("","900: %p 2760: %p 7000: %p 8000: %p", 
       h0900, h2760, h7000, h8000);
  Double_t e8000 = (trigger.EqualTo("INEL") ? 0.852 : 0.93);
  h8000->Scale(e8000);

  TFile* out = TFile::Open("trends.root", "RECREATE");
  THStack* sOrig = new THStack("orig", Form("pp - %s", trigger.Data()));
  sOrig->Add(h8000);
  sOrig->Add(h7000);
  sOrig->Add(h2760);
  sOrig->Add(h0900);

  TCanvas* cOrig = new TCanvas("cOrig", "Original", 1200, 1200);
  cOrig->SetTopMargin(0.01);
  cOrig->SetRightMargin(0.01);
  sOrig->Draw("nostack");
  sOrig->GetHistogram()->SetYTitle("1/#it{N} d#it{N}_{ch}/d#it{#eta}");
  sOrig->GetHistogram()->SetXTitle("#it{#eta}");
  sOrig->DrawClone("nostack");
  sOrig->Write();
  
  TLegend* l = cOrig->BuildLegend(.35, .2, .55, .6, "#sqrt{s}");
  l->SetFillColor(0);
  l->SetFillStyle(0);
  l->SetBorderSize(0);

  cOrig->Modified();
  cOrig->Update();
  cOrig->cd();
  cOrig->Write();
  Info("", "Wrote original"); 

  TCanvas* cG = new TCanvas("cG", "one", 1200, 1200);
  cG->SetTopMargin(0.01);
  cG->SetRightMargin(0.01);
  
  Info("","Creating tuple");
  TNtuple* tuple = new TNtuple("tuple", "Tuple", 
			       "eta:deta:"
			       "v0900:e0900:v2760:e2760:"
			       "v7000:e7000:v8000:e8000");
  TMultiGraph* mg = new TMultiGraph;
  Int_t n = h0900->GetNbinsX();
  Info("","Loop over bins %d", n);

  for (Int_t i = 1; i <= n; i++) {
    Info("", "Getting one bin %d,%p,%p,%p,%p,%p,%p",
	 i, h0900,h2760,h7000,h8000,mg,tuple);
    OneBin(i, h0900, h2760, h7000, h8000, mg, tuple);
  }
  mg->Draw("alp");

  cG->Modified();
  cG->Update();
  cG->cd();

  TPrincipal* p =tuple->Principal("v0900:v2760:v7000:v8000","eta<0", "npdhc");
}
开发者ID:ktf,项目名称:AliPhysics,代码行数:72,代码来源:Interpolate.C


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