本文整理汇总了C++中TH1F::SetFillColor方法的典型用法代码示例。如果您正苦于以下问题:C++ TH1F::SetFillColor方法的具体用法?C++ TH1F::SetFillColor怎么用?C++ TH1F::SetFillColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TH1F
的用法示例。
在下文中一共展示了TH1F::SetFillColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compnclusts
void compnclusts(Int_t run)
{
TFile* f = new TFile(Form("hodtest_%d.root",run));
cout << "hcana root file " << Form("hodtest_%d.root",run) << endl;
TH1F* h = nclust;
TFile* f1 = new TFile(Form("%d_hbk.root",run));
cout << "Engine root file " << Form("%d_hbk.root",run) << endl;
TH1F* h1;
switch (run) {
case 50017 :
// h1 = h212; //A+
break;
default :
h1 = h412; //hnclusters
}
TCanvas *c1 = new TCanvas("c1", "Shower Cluster Map", 1000, 667);
gPad->SetLogy();
h1->SetFillColor(kGreen);
h1->SetLineColor(kGreen);
h1->SetFillStyle(1111);
h1->Draw();
h->SetFillColor(kBlue);
h->SetLineWidth(2);
h->SetFillStyle(0);
h->Draw("same");
TLatex l;
l.SetTextSize(0.04);
Float_t maxy = h1->GetBinContent(h1->GetMaximumBin());
Float_t xmin = h1->GetXaxis()->GetXmin();
Float_t xmax = h1->GetXaxis()->GetXmax();
Float_t xt = xmin + 0.67*(xmax-xmin);
l.SetTextColor(kGreen);
l.DrawLatex(xt,0.095*maxy,"Engine");
l.SetTextColor(kBlue);
l.DrawLatex(xt,0.045*maxy,"hcana");
// Difference between the histograms.
TCanvas *c2 = new TCanvas("c2", "Cluster differences", 1000, 667);
TH1F* dif = h->Clone();
dif->Add(h,h1,1.,-1.);
dif->SetTitle("Difference");
dif->SetFillColor(kRed);
dif->SetLineColor(kRed);
dif->SetLineWidth(1);
dif->SetFillStyle(1111);
dif->Draw();
}
示例2: Terminate
//_____________________________________________________________________________
void ProofEventProc::Terminate()
{
// The Terminate() function is the last function to be called during
// a query. It always runs on the client, it can be used to present
// the results graphically or save the results to file.
// Check ranges
CheckRanges();
if (gROOT->IsBatch()) return;
TCanvas* canvas = new TCanvas("event","event",800,10,700,780);
canvas->Divide(2,2);
TPad *pad1 = (TPad *) canvas->GetPad(1);
TPad *pad2 = (TPad *) canvas->GetPad(2);
TPad *pad3 = (TPad *) canvas->GetPad(3);
TPad *pad4 = (TPad *) canvas->GetPad(4);
// The number of tracks
pad1->cd();
pad1->SetLogy();
TH1F *hi = dynamic_cast<TH1F*>(fOutput->FindObject("pz_dist"));
if (hi) {
hi->SetFillColor(30);
hi->SetLineColor(9);
hi->SetLineWidth(2);
hi->DrawCopy();
} else { Warning("Terminate", "no pz dist found"); }
// The Pt distribution
pad2->cd();
pad2->SetLogy();
TH1F *hf = dynamic_cast<TH1F*>(fOutput->FindObject("pt_dist"));
if (hf) {
hf->SetFillColor(30);
hf->SetLineColor(9);
hf->SetLineWidth(2);
hf->DrawCopy();
} else { Warning("Terminate", "no pt dist found"); }
// The Px,Py distribution, color surface
TH2F *h2f = dynamic_cast<TH2F*>(fOutput->FindObject("px_py"));
if (h2f) {
// Color surface
pad3->cd();
h2f->DrawCopy("SURF1 ");
// Lego
pad4->cd();
h2f->DrawCopy("CONT2COL");
} else {
Warning("Terminate", "no px py found");
}
// Final update
canvas->cd();
canvas->Update();
}
示例3: dataMC
void dataMC() {
double xmin = 60.0;
double xmax = 160.0;
int nbins = 200;
TCanvas* c = new TCanvas("c", "c", 600, 600);
std::string hfile = "/home/avartak/CMS/HMuMu/CMSSW_8_0_26_patch1/src/HMuMuAnalysis/AnalysisStep/trees/GluGlu_HToMuMu_M125_13TeV_powheg_pythia8/trim.root";
std::string zfile = "/home/avartak/CMS/HMuMu/CMSSW_8_0_26_patch1/src/HMuMuAnalysis/AnalysisStep/trees/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8/trim.root";
std::string tfile = "/home/avartak/CMS/HMuMu/CMSSW_8_0_26_patch1/src/HMuMuAnalysis/AnalysisStep/trees/TTJets_Dilept_TuneCUETP8M2T4_13TeV-amcatnloFXFX-pythia8/trim.root";
std::string dfile = "/home/avartak/CMS/HMuMu/CMSSW_8_0_26_patch1/src/HMuMuAnalysis/AnalysisStep/trees/SingleMuon/trim.root";
TFile* fileh = new TFile(hfile.c_str());
TFile* filez = new TFile(zfile.c_str());
TFile* filet = new TFile(tfile.c_str());
TFile* filed = new TFile(dfile.c_str());
TH1F* histh = new TH1F("histh", "", nbins, xmin, xmax);
TH1F* histz = new TH1F("histz", "", nbins, xmin, xmax);
TH1F* histt = new TH1F("histt", "", nbins, xmin, xmax);
TH1F* histd = new TH1F("histd", "", nbins, xmin, xmax);
TTree* treeh = (TTree*)fileh->Get("tree");
TTree* treez = (TTree*)filez->Get("tree");
TTree* treet = (TTree*)filet->Get("tree");
TTree* treed = (TTree*)filed->Get("tree");
treez->Draw("mass>>histz", "(cat > 0) * wgt");
treet->Draw("mass>>histt", "(cat > 0) * wgt");
treed->Draw("mass>>histd", "(cat > 0 && (mass < 120 || mass > 130))");
histz->SetFillColor(kCyan+1);
histt->SetFillColor(kOrange+1);
histz->SetLineWidth(2);
histt->SetLineWidth(2);
histh->SetLineWidth(2);
histz->Add(histt);
histz->Draw("HIST");
histt->Draw("HIST SAME");
histd->Draw("PE SAME");
c->RedrawAxis();
}
示例4: DrawOverflow
TH1F * DrawOverflow(TH1F *h)
{
// This function paint the histogram h with an extra bin for overflows
UInt_t nx = h->GetNbinsX()+1;
Double_t *xbins= new Double_t[nx+1];
for (UInt_t i=0;i<nx;i++)
xbins[i]=h->GetBinLowEdge(i+1);
xbins[nx]=xbins[nx-1]+h->GetBinWidth(nx);
char *tempName= new char[strlen(h->GetName())+10];
sprintf(tempName,"%swtOverFlow",h->GetName());
// Book a temporary histogram having ab extra bin for overflows
TH1F *htmp = new TH1F(tempName, h->GetTitle(), nx, xbins);
// Reset the axis labels
htmp->SetXTitle(h->GetXaxis()->GetTitle());
htmp->SetYTitle(h->GetYaxis()->GetTitle());
// Fill the new hitogram including the extra bin for overflows
for (UInt_t i=1; i<=nx; i++)
htmp->Fill(htmp->GetBinCenter(i), h->GetBinContent(i));
// Fill the underflows
htmp->Fill(h->GetBinLowEdge(1)-1, h->GetBinContent(0));
// Restore the number of entries
htmp->SetEntries(h->GetEntries());
// FillStyle and color
htmp->SetFillStyle(h->GetFillStyle());
htmp->SetFillColor(h->GetFillColor());
return htmp;
}
示例5: TCanvas
// 1-D histograms with alphanumeric labels
// author; Rene Brun
TCanvas *hlabels1()
{
const Int_t nx = 20;
const char *people[nx] = {"Jean","Pierre","Marie","Odile","Sebastien",
"Fons","Rene","Nicolas","Xavier","Greg","Bjarne","Anton","Otto",
"Eddy","Peter","Pasha","Philippe","Suzanne","Jeff","Valery"};
TCanvas *c1 = new TCanvas("c1","demo bin labels",10,10,900,500);
c1->SetGrid();
c1->SetTopMargin(0.15);
TH1F *h = new TH1F("h","test",3,0,3);
h->SetStats(0);
h->SetFillColor(38);
h->SetCanExtend(TH1::kAllAxes);
for (Int_t i=0;i<5000;i++) {
Int_t r = gRandom->Rndm()*20;
h->Fill(people[r],1);
}
h->LabelsDeflate();
h->Draw();
TPaveText *pt = new TPaveText(0.7,0.85,0.98,0.98,"brNDC");
pt->SetFillColor(18);
pt->SetTextAlign(12);
pt->AddText("Use the axis Context Menu LabelsOption");
pt->AddText(" \"a\" to sort by alphabetic order");
pt->AddText(" \">\" to sort by decreasing values");
pt->AddText(" \"<\" to sort by increasing values");
pt->Draw();
return c1;
}
示例6: labels1
void labels1()
{
Int_t i;
const Int_t nx = 20;
const char *people[nx] = {"Jean","Pierre","Marie","Odile",
"Sebastien","Fons","Rene","Nicolas","Xavier","Greg",
"Bjarne","Anton","Otto","Eddy","Peter","Pasha",
"Philippe","Suzanne","Jeff","Valery"};
TCanvas *c1 = new TCanvas("c1","demo bin labels",10,10,900,500);
c1->SetGrid();
c1->SetBottomMargin(0.15);
TH1F *h = new TH1F("h","test",nx,0,nx);
h->SetFillColor(38);
for (i=0;i<5000;i++) h->Fill(gRandom->Gaus(0.5*nx,0.2*nx));
h->SetStats(0);
for (i=1;i<=nx;i++) h->GetXaxis()->SetBinLabel(i,people[i-1]);
h->Draw();
TPaveText *pt = new TPaveText(0.6,0.7,0.98,0.98,"brNDC");
pt->SetFillColor(18);
pt->SetTextAlign(12);
pt->AddText("Use the axis Context Menu LabelsOption");
pt->AddText(" \"a\" to sort by alphabetic order");
pt->AddText(" \">\" to sort by decreasing values");
pt->AddText(" \"<\" to sort by increasing values");
pt->Draw();
}
示例7: Difference
void Difference(TH1* iH0,TH1 *iH1) {
std::string lName = std::string(iH0->GetName());
//TH1F *lHDiff = new TH1F((lName+"Diff").c_str(),(lName+"Diff").c_str(),50,0,300); lHDiff->Sumw2();
TH1F *lHDiff = new TH1F((lName+"Diff").c_str(),(lName+"Diff").c_str(),iH0->GetNbinsX(),iH0->GetXaxis()->GetXmin(),iH0->GetXaxis()->GetXmax()); lHDiff->Sumw2();
lHDiff->SetFillColor(kViolet); lHDiff->SetFillStyle(1001); lHDiff->SetLineWidth(1);
TH1F *lXHDiff1 = new TH1F((lName+"XDiff1").c_str(),(lName+"XDiff1").c_str(),iH0->GetNbinsX(),iH0->GetXaxis()->GetXmin(),iH0->GetXaxis()->GetXmax());
int i1 = 0;
lXHDiff1->SetLineStyle(2); lXHDiff1->SetLineWidth(2); lXHDiff1->SetLineColor(kRed);
lHDiff->GetYaxis()->SetRangeUser(0,2);
lHDiff->GetYaxis()->SetTitleOffset(0.6);
lHDiff->GetYaxis()->SetTitleSize(0.08);
lHDiff->GetYaxis()->SetLabelSize(0.08);
lHDiff->GetYaxis()->CenterTitle();
lHDiff->GetXaxis()->SetTitleOffset(1.2);
lHDiff->GetXaxis()->SetTitleSize(0.10);
lHDiff->GetXaxis()->SetLabelSize(0.08);
lHDiff->GetXaxis()->SetTitle("#slash{E}_{T} [GeV]");
//lHDiff->GetXaxis()->CenterTitle();
//lHDiff->GetYaxis()->SetTitle(YLabel);
for(int i0 = 0; i0 < lHDiff->GetNbinsX()+1; i0++) {
double lXCenter = lHDiff->GetBinCenter(i0);
double lXVal = iH0 ->GetBinContent(i0);
lXHDiff1->SetBinContent(i0, 1.0);
while(iH1->GetBinCenter(i1) < lXCenter) {i1++;}
if(iH1->GetBinContent(i0) > 0) lHDiff->SetBinContent(i0,(lXVal-iH1->GetBinContent(i0))/(iH1->GetBinContent(i0)));
if(iH1->GetBinContent(i0) > 0) lHDiff->SetBinError (i0,iH0->GetBinError(i0)/(iH1->GetBinContent(i0)));
}
lHDiff->SetMarkerStyle(kFullCircle); lHDiff->SetLineColor(kBlack); lHDiff->SetMarkerColor(kBlack);
lHDiff->Draw("E1");
lXHDiff1->Draw("hist sames");
}
示例8: GetTreeSize
void GetTreeSize(TString FileName, TString TreeName)
{
TFile *inf = TFile::Open(FileName);
TTree *tr = (TTree*)inf->Get(TreeName);
TObjArray *branches = (TObjArray*)tr->GetListOfBranches();
int size(0);
cout.setf(ios::right);
int N(branches->GetEntries());
TH1F *hSize = new TH1F("size","size",N,0,N);
for(int ib=0;ib<N;ib++) {
TString name(branches->At(ib)->GetName());
TBranch *br = (TBranch*)tr->GetBranch(name);
hSize->Fill(name,br->GetZipBytes()/1e+3);
size += br->GetZipBytes();
}
cout<<"Total size: "<<size<<endl;
for(int ib=0;ib<N;ib++) {
TString name(branches->At(ib)->GetName());
TBranch *br = (TBranch*)tr->GetBranch(name);
float percent = TMath::Ceil(1000*float(br->GetZipBytes())/float(size))/10;
cout<<ib<<setw(20)<<name<<setw(15)<<br->GetZipBytes()<<" "<<percent<<"%"<<endl;
}
TCanvas *can = new TCanvas("TreeSize","TreeSize",1000,400);
hSize->GetXaxis()->SetTitle("Branch Name");
hSize->GetXaxis()->SetLabelSize(0.04);
hSize->GetYaxis()->SetTitle("Size (KB)");
hSize->SetFillColor(kGray);
hSize->Draw();
}
示例9: SetSignalStyle
void SetSignalStyle(TH1F & ele, unsigned color) {
ele.SetFillStyle(1001);
ele.SetLineStyle(11);
ele.SetFillColor(0);
ele.SetLineColor(color);
ele.SetLineWidth(2);
return;
}
示例10: PlotHistsNhitsPerModule
void PlotHistsNhitsPerModule(TFile* f, TTree* tr, TString strMillepedeRes, TString strOutdir)
{
TString canvName="c_";
canvName+=strMillepedeRes;
canvName+="_";
canvName+=StrPlotType(NHITS);
canvName.ReplaceAll(".res","");
//enum {PXB,PXF,TIB,TID,TOB,TEC};
int colors[6]={1,2,3,4,6,7};
// TString labels[6]={"PXB","PXF","TIB","TID","TOB","TEC"};
f->cd();
TCanvas* canv = new TCanvas(canvName,canvName,600,600);
canv->SetLogx();
canv->SetLogy();
for (int ind=1; ind<=1; ind++){
TString strHist = "hNhits_";
strHist+=StrPar(ind);
TString strCut="label<700000 && ((label%20-1)%9+1)==";
strCut+=ind;
TStyle style;
style.SetTitleFontSize(0.2);
THStack *hSt = new THStack("hNhits","# of derivatives (~tracks or hits) per module");
TLegend *leg = new TLegend(0.75,0.65,0.95,0.95);
for (int inv=0; inv<6; inv++){
std::cout<<"- - - - - -"<<std::endl;
std::cout<<subdLabels[inv]<<":"<<std::endl;
std::cout<<StrCutSubd(inv)<<": "<<tr->GetEntries(StrCutSubd(inv))<<" parameters"<<std::endl;
TString strHist1=strHist;
strHist1+=ind;
strHist1+=inv;
TH1F* hValInt = new TH1F(strHist1,strHist1,300,10,15000);
TString strCut1 = strCut+TString(" && ")+StrCutSubd(inv);
tr->Draw(TString("Nhits>>")+strHist1,strCut1,"goff");
std::cout<<"# hits = "<<(int)hValInt->GetMean()<<"+-"<<(int)hValInt->GetRMS()<<std::endl;
hValInt->SetLineColor(1);
hValInt->SetFillColor(colors[inv]);
hValInt->SetLineWidth(2);
hSt->Add(hValInt);
leg->AddEntry(hValInt,subdLabels[inv],"f");
leg->SetFillColor(0);
}
hSt->Draw();
leg->Draw("same");
}//end of loop over ind
canvName+=".png";
TString saveName=strOutdir+canvName;
canv->SaveAs(saveName);
saveName.ReplaceAll(".png",".pdf");
canv->SaveAs(saveName);
}//end of PlotHistsNhitsPerModule
示例11: SetDataStyle
void SetDataStyle(TH1F & ele) {
ele.SetMarkerColor(1);
ele.SetLineColor(1);
ele.SetFillColor(1);
ele.SetFillStyle(0);
ele.SetLineWidth(2);
ele.SetMarkerStyle(20);
ele.SetMarkerSize(1.1);
return;
}
示例12: plot
TCanvas * plot (TH1F* histoDataIn, TString legendData, TH1F* histoSimulationIn, TString legendSimulation,
TString & canvasName, Float_t maximum = 0.15, TString xAxisTitle = "#eta",
TString yAxisTitle = "Number of Clusters", TString error = "", bool useLegend = true,
TString text = "", Float_t textX = 0.7, Float_t textY = 0.4, Float_t rebin = 0 ) {
TH1F * histoData = (TH1F*)histoDataIn->Clone();
TH1F * histoSimulation = (TH1F*)histoSimulationIn->Clone();
// histoData->Sumw2();
histoData->Scale(1/(histoData->Integral()));
histoSimulation->Scale(1/(histoSimulation->Integral()));
// Create also the legend and add the histograms
TLegend * legend = new TLegend( 0.55, 0.65, 0.76, 0.82 );
legend->AddEntry( histoData, xAxisTitle );
legend->AddEntry( histoSimulation, yAxisTitle, "F" );
cout << "histoData = " << histoData << endl;
cout << "histoSimulation = " << histoSimulation << endl;
TCanvas * c = new TCanvas( canvasName, canvasName, 1000, 800 );
c->Draw();
histoSimulation->SetMaximum(maximum);
histoSimulation->SetFillColor(kRed);
// histoSimulation->SetLineWidth(0);
histoSimulation->SetLineColor(kRed);
histoSimulation->SetXTitle(xAxisTitle);
histoSimulation->SetYTitle(yAxisTitle);
histoSimulation->SetTitleOffset(1.6,"Y");
histoSimulation->SetTitle();
histoData->SetLineStyle(1);
histoData->SetLineWidth(2.5);
histoSimulation->Draw();
histoData->Draw("same");
legend->SetFillColor(kWhite);
if (useLegend) legend->Draw("same");
if ( text != "" ) {
TPaveText * pt = new TPaveText(textX, textY, textX+0.2, textY+0.17, "NDC" ); // "NDC" option sets coords relative to pad dimensions
pt->SetFillColor(0); // text is black on white
pt->SetTextSize(0.08);
pt->SetBorderSize(0);
pt->SetTextAlign(12);
pt->AddText(text);
pt->Draw("same"); //to draw your text object
}
return c;
};
示例13: superimposeHistos
void superimposeHistos()
{
TFile* bFile = TFile::Open("Electron_In_Jets_900GeV_bJets.root");
TFile* cFile = TFile::Open("Electron_In_Jets_900GeV_cJets.root");
TFile* udsgFile = TFile::Open("Electron_In_Jets_900GeV_udsgJets.root");
TIter next(bFile->GetListOfKeys());
TFile* newFile = new TFile("testFile.root", "RECREATE");
while(TKey* key = (TKey*)next())
{
TH1F* bHist = (TH1F*)bFile->Get(key->GetName());
bHist->SetFillColor(2);
TH1F* cHist = (TH1F*)cFile->Get(key->GetName());
cHist->SetFillColor(3);
TH1F* udsgHist = (TH1F*)udsgFile->Get(key->GetName());
udsgHist->SetFillColor(4);
THStack* stack = new THStack(bHist->GetName(), bHist->GetTitle());
stack->Add(udsgHist, "hist ][");
stack->Add(cHist, "hist ][");
stack->Add(bHist, "hist ][");
TLegend* legend = new TLegend(0.5, 0.68, 0.88, 0.88);
legend->AddEntry(bHist, "b-Jets");
legend->AddEntry(cHist, "c-Jets");
legend->AddEntry(udsgHist, "udsg-Jets");
TCanvas* canvas = new TCanvas(bHist->GetName());
stack->Draw();
stack->GetXaxis()->SetTitle(bHist->GetXaxis()->GetTitle());
legend->Draw();
canvas->Write(canvas->GetName());
}
newFile->Close();
bFile->Close();
cFile->Close();
udsgFile->Close();
}
示例14: AddHist
TH1F * AddHist(THStack *stack, TLegend * leg, TFile *f, const char * name, const char * sample, const char * legsamp, int style, int color){
char full_name[200];
sprintf(full_name, "%s_%s", name, sample);
TH1F * h = (TH1F *)f->Get(full_name);
if (h){
h->SetFillStyle(style);
h->SetLineColor(color);
h->SetFillColor(color);
if (leg) { leg->AddEntry(h, legsamp, "f"); }
stack->Add(h);
}
return h;
}
示例15: performClosure
void performClosure(RooRealVar *mass, RooAbsPdf *pdf, RooDataSet *data, string closurename, double wmin=110., double wmax=130., double slow=110., double shigh=130., double step=0.002) {
// plot to perform closure test
cout << "Performing closure test..." << endl;
double nbins = (wmax-wmin)/step;
TH1F *h = new TH1F("h","h",int(floor(nbins+0.5)),wmin,wmax);
if (data){
pdf->fillHistogram(h,RooArgList(*mass),data->sumEntries());
h->Scale(2*h->GetNbinsX()/double(binning_));
}
else {
pdf->fillHistogram(h,RooArgList(*mass));
}
int binLow = h->FindBin(slow);
int binHigh = h->FindBin(shigh)-1;
TH1F *copy = new TH1F("copy","c",binHigh-binLow,h->GetBinLowEdge(binLow),h->GetBinLowEdge(binHigh+1));
for (int b=0; b<copy->GetNbinsX(); b++) copy->SetBinContent(b+1,h->GetBinContent(b+1+binLow));
double areaCov = 100*h->Integral(binLow,binHigh)/h->Integral();
// style
h->SetLineColor(kBlue);
h->SetLineWidth(3);
h->SetLineStyle(7);
copy->SetLineWidth(3);
copy->SetFillColor(kGray);
TCanvas *c = new TCanvas();
if (data){
RooPlot *plot = mass->frame(Bins(binning_),Range("higgsRange"));
plot->addTH1(h,"hist");
plot->addTH1(copy,"same f");
if (data) data->plotOn(plot);
pdf->plotOn(plot,Normalization(h->Integral(),RooAbsReal::NumEvent),NormRange("higgsRange"),Range("higgsRange"),LineWidth(1),LineColor(kRed),LineStyle(kDashed));
plot->Draw();
c->Print(closurename.c_str());
}
else {
RooPlot *plot = mass->frame(Bins(binning_),Range("higgsRange"));
h->Scale(plot->getFitRangeBinW()/h->GetBinWidth(1));
copy->Scale(plot->getFitRangeBinW()/h->GetBinWidth(1));
pdf->plotOn(plot,LineColor(kRed),LineWidth(3));
plot->Draw();
h->Draw("hist same");
copy->Draw("same f");
c->Print(closurename.c_str());
}
cout << "IntH: [" << h->GetBinLowEdge(binLow) << "-" << h->GetBinLowEdge(binHigh+1) << "] Area = " << areaCov << endl;
delete c;
delete copy;
delete h;
}