本文整理汇总了C++中TGraph::GetHistogram方法的典型用法代码示例。如果您正苦于以下问题:C++ TGraph::GetHistogram方法的具体用法?C++ TGraph::GetHistogram怎么用?C++ TGraph::GetHistogram使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TGraph
的用法示例。
在下文中一共展示了TGraph::GetHistogram方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: plot
/**
* \brief Plots the data
* Plots the data in data_x and data_y
* \param bool autox , bool autoy actually not needed ;)
* \return bool on success
*/
bool Plotter::plot(bool autox , bool autoy){
for(size_t j = 0 ; j< graph.size(); j++){
try{
TGraph *gr = graph[j].get();
for(size_t i = 0; i < data_x.size(); i++){
gr->SetPoint(i,data_x[i], data_y[i]);
}
if(!opt.autox){
gr->GetHistogram()->GetXaxis()->SetRangeUser(opt.startx, opt.stopx);
}
if(!opt.autoy){
gr->GetHistogram()->GetYaxis()->SetRangeUser(opt.starty, opt.stopy);
}
gr->SetMarkerSize(0.2);
gr->GetHistogram()->SetXTitle(opt.xlabel.c_str());
gr->GetHistogram()->SetYTitle(opt.ylabel.c_str());
gr->SetTitle(opt.plot_name.c_str());
gr->Draw("A*");
}catch(std::runtime_error &e){
std::cerr << e.what() << std::endl;
return false;
}
}
return true;
}
示例2: laserCalibration
//.........这里部分代码省略.........
posxa=5;
posxb=7;
break;
case 1086:
posxa=5;
posxb=5;
break;
case 1087:
posxa=4;
posxb=4;
break;
case 1088:
posxa=3;
posxb=4;
break;
case 1089:
posxa=3;
posxb=3;
break;
default:
posxa=6;
posxb=9;
}
integralP2 = g->Integral (fPositionX2-posxa,fPositionX2+posxb);
/**************************************
* print and update the canvas
**************************************
*/
if(gui==true){
TH1F* gh = g->GetHistogram();
gh->FillN(nbins,g->GetX(),g->GetY());
g->Draw();
TPolyMarker* pm = (TPolyMarker*)gh->GetListOfFunctions()->FindObject("TPolyMarker");
if (pm) {
gh->GetListOfFunctions()->Remove(pm);
delete pm;
}
pm = new TPolyMarker(nfound, px, py);
gh->GetListOfFunctions()->Add(pm);
pm->SetMarkerStyle(23);
pm->SetMarkerColor(kBlue);
pm->SetMarkerSize(1.3);
for (i = 0; i < nbins; i++) d->SetBinContent(i,dest[i]);
d->SetLineColor(kRed);
d->Draw("SAME");
for (i = 0; i < nbins; i++) back->SetBinContent(i,baseline[i]);
back->SetLineColor(kGreen);
back->Draw("SAME");
c1->Update();
}
/**************************************
* Fill tree and peaks data Histogram
**************************************
*/
if(nfound==2)
{
lmPeaks->Fill(integralP2);
outTree->Fill();
}
//printf("time= %d, posx1= %d, posy1= %d\n",time, fPositionX1, fPositionY1);
//printf("time= %d, posx2= %d, posy2= %d\n",time, fPositionX2, fPositionY2);
//for (int i=0;i<nbins;i++) printf("time = %d\n",baseline[i]);
}
}
/**************************************
* switch to the bottom pan and Draw Histogram
**************************************
*/
c1->cd(2);
//lmPeaks->SetAxisRange(TMath::MinElement(entries,binmin),TMath::MaxElement(entries,binmax)+100);
//lmPeaks->SetAxisRange(0,3000);
lmPeaks->Fit("gaus");
integralP2_mean = lmPeaks->GetFunction("gaus")->GetParameter(1);
integralP2_sigma = lmPeaks->GetFunction("gaus")->GetParameter(2);
integralP2_mean_error = lmPeaks->GetFunction("gaus")->GetParError(1);
integralP2_sigma_error = lmPeaks->GetFunction("gaus")->GetParError(2);
//printf("mean = %f\n",integralP2_mean);
//printf("sigma = %f\n",integralP2_sigma);
calibTree->Fill();
lmPeaks->Draw();
c1->Update();
outfile->cd();
gROOT->GetList()->Write();
outTree->Write();
calibTree->Write();
outfile->Close();
}
示例3: connect
//.........这里部分代码省略.........
// add a help menu
Q3PopupMenu * help = new Q3PopupMenu( this );
menuBar()->insertSeparator();
menuBar()->insertItem( "&Help", help );
help->insertItem( "&About", this, SLOT(about()), Qt::Key_F1 );
help->insertItem( "About &Qt", this, SLOT(aboutQt()) );
help->insertSeparator();
help->insertItem( "What's &This", this, SLOT(whatsThis()), Qt::SHIFT+Qt::Key_F1 );
// create and define the ROOT Canvas central widget
tab = new QTabWidget(this);
tab->show();
setCentralWidget( tab );
Q3MainWindow *win1 = new Q3MainWindow( 0, "tab1 main window", Qt::WDestructiveClose );
Q3MainWindow *win2 = new Q3MainWindow( 0, "tab2 main window", Qt::WDestructiveClose );
aCanvas = new TQRootCanvas(this, win1,"Qt&Root");
aCanvas2 = new TQRootCanvas(this, win2,"Qt&Root");
win1->setCentralWidget(aCanvas);
win2->setCentralWidget(aCanvas2);
tab->addTab(win1,"page1");
tab->addTab(win2,"page2");
win1->show();
win2->show();
// with no QTabWidget
// aCanvas = new TQRootCanvas(this,"Qt&Root");
// setCentralWidget( aCanvas );
resize( 450, 500 );
// put here some ROOT Specifics ...
if (aCanvas->GetCanvas()) {
aCanvas->GetCanvas()->Resize();
aCanvas->GetCanvas()->SetFillColor(40);
aCanvas->GetCanvas()->cd();
pad1 = new TPad("pad1","The pad with the function",0.05,0.50,0.95,0.95,21);
pad1->Draw();
pad1->cd();
pad1->SetGridx();
pad1->SetGridy();
pad1->GetFrame()->SetFillColor(42);
pad1->GetFrame()->SetBorderMode(-1);
pad1->GetFrame()->SetBorderSize(5);
histo= new TH1F("hppx","Gaussian distribution",100,-4,4);
histo->SetFillColor(0);
histo->Draw();
aCanvas->GetCanvas()->cd();
pad2 = new TPad("pad2","The pad with the histogram",0.05,0.05,0.95,0.45,21);
pad2->Draw();
pad2->cd();
form1 = new TFormula("form1","abs(sin(x)/x)");
sqroot = new TF1("sqroot","x*gaus(0) + [3]*form1",0,10);
sqroot->SetParameters(10,4,1,20);
sqroot->SetLineColor(4);
sqroot->SetLineWidth(6);
sqroot->Draw();
} // ! aCAnvas
if (aCanvas2) {
TCanvas *c1 = aCanvas2->GetCanvas();
c1->Resize();
c1->SetFillColor(42);
c1->GetFrame()->SetFillColor(21);
c1->GetFrame()->SetBorderSize(12);
c1->cd();
//graph example
const Int_t n = 20;
Double_t x[n], y[n];
for (Int_t i=0;i<n;i++) {
x[i] = i*0.1;
y[i] = 10*TMath::Sin(x[i]+0.2);
// printf(" i %i %f %f \n",i,x[i],y[i]);
}
TGraph* gr = new TGraph(n,x,y);
gr->SetLineColor(2);
gr->SetLineWidth(4);
gr->SetMarkerColor(4);
gr->SetMarkerStyle(21);
gr->SetTitle("a simple graph");
gr->Draw("ACP");
gr->GetHistogram()->SetXTitle("X title");
gr->GetHistogram()->SetYTitle("Y title");
c1->Modified();
c1->Update();
} //!aCanvas2
}
示例4: Plot_sWeights
void Fitter::Plot_sWeights()
{
vector<TGraph*> vec_pGraph;
vector<vector<double>* > vec_pVec_values;
Interval yRange(0., 0.);
for(auto& pVec_pdfs : {&sigPdfs, &bkgPdfs})
for(auto& pdf : *pVec_pdfs)
{
RooAbsReal& yield = pdf.GetYld();
int nEvents = pData->numEntries();
vector<double>* px = new vector<double>;
vector<double>* py = new vector<double>;
TGraph* pGraph = NULL;
vector<tuple<double, double> > points(nEvents, make_tuple(0., 0.));
for(int i=0; i<nEvents; ++i) //nSWeights
{
double x = pData->get(i)->getRealValue(pFitVar->GetName());
double y = pSPlot->GetSWeight(i, yield.GetName());
points[i] = make_tuple(x, y);
if(y > yRange.maximum) yRange.maximum = y;
if(y < yRange.minimum) yRange.minimum = y;
}
sort(points.begin(), points.end(), [](const tuple<double, double>& p, const tuple<double, double>& q){ return get<0>(p) < get<0>(q); });
for(auto& p : points)
{
px->push_back(get<0>(p));
py->push_back(get<1>(p));
}
pGraph = new TGraph(nEvents, &px->at(0), &py->at(0));
vec_pGraph.push_back(pGraph);
vec_pVec_values.push_back(px);
vec_pVec_values.push_back(py);
}
yRange = GetNiceLimits(yRange);
//TFile* pFile = new TFile(outputFilename.c_str(), "UPDATE");
//TDirectory* pSPlotDir = pFile->GetDirectory("sWeightPlots");
TCanvas* pCanvas = new TCanvas("sWeight_plot", "sWeight_plot", 800, 600);
TLegend* pLegend = new TLegend(0.65, 0.65, 0.99, 0.93);
//if(!pSPlotDir) pSPlotDir = pFile->mkdir("sWeightPlots");
pLegend->SetTextSize(0.035);
for(size_t i=0; i<vec_pGraph.size(); ++i)
{
TGraph* pGraph = vec_pGraph[i];
RooAbsReal& yield = (i<sigPdfs.size()?sigPdfs[i]:bkgPdfs[i-sigPdfs.size()]).GetYld();
pGraph->SetLineWidth(2);
//pGraph->GetHistogram()->SetMarkerColorAlpha(kWhite, 1.);
pGraph->GetHistogram()->SetFillColor(10);
pGraph->SetFillColor(10);
pGraph->GetHistogram()->SetTitle(("sWeight vs " + plotAxisLabel).c_str());
pGraph->SetLineColor(i+1);
pGraph->GetXaxis()->SetTitle(plotAxisLabel.c_str());
pGraph->GetHistogram()->SetMinimum(yRange.minimum);
pGraph->GetHistogram()->SetMaximum(yRange.maximum);
pGraph->GetHistogram()->GetYaxis()->SetTitle("sWeight");
pGraph->Draw(i?"same":"");
pLegend->AddEntry(pGraph, (yield.GetName()+string("_sw")).c_str());
pLegend->Draw("L");
}
ChangeDirectory();
pCanvas->Write();
delete pLegend;
delete pCanvas;
//delete pFile;
for(auto& pVec : vec_pVec_values) delete pVec;
for(auto& pGraph : vec_pGraph) delete pGraph;
}
示例5: calculatePadBoundaries
PadBoundaries PlotBundle::calculatePadBoundaries() const {
PadBoundaries union_pad_boundaries;
bool nothing_drawn(true);
std::vector<DrawableDataObjectDrawOptionPair<TH1*> >::const_iterator hist_it;
for (hist_it = histograms.begin(); hist_it != histograms.end(); hist_it++) {
TH1* hist = hist_it->data_object;
std::string draw_option(hist_it->draw_option);
if (hist) {
hist->Draw(draw_option.c_str());
if (plot_axis.x_axis_range.active)
hist->GetXaxis()->SetRangeUser(plot_axis.x_axis_range.low,
plot_axis.x_axis_range.high);
PadBoundaries current_pad_boundaries(*hist);
if (nothing_drawn) {
union_pad_boundaries = current_pad_boundaries;
nothing_drawn = false;
} else {
union_pad_boundaries = union_pad_boundaries.getUnionBoundaries(
current_pad_boundaries);
}
}
}
std::vector<DrawableDataObjectDrawOptionPair<TGraph*> >::const_iterator graph_it;
for (graph_it = graphs.begin(); graph_it != graphs.end(); graph_it++) {
TGraph* graph = graph_it->data_object;
std::string draw_option("A");
draw_option.append(graph_it->draw_option);
if (graph) {
graph->Draw(draw_option.c_str());
if (plot_axis.x_axis_range.active)
graph->GetXaxis()->SetRangeUser(plot_axis.x_axis_range.low,
plot_axis.x_axis_range.high);
PadBoundaries current_pad_boundaries(*graph->GetHistogram());
if (nothing_drawn) {
union_pad_boundaries = current_pad_boundaries;
nothing_drawn = false;
} else {
union_pad_boundaries = union_pad_boundaries.getUnionBoundaries(
current_pad_boundaries);
}
}
}
std::vector<DrawableDataObjectDrawOptionPair<TGraph2D*> >::const_iterator graph2d_it;
for (graph2d_it = graphs2d.begin(); graph2d_it != graphs2d.end();
graph2d_it++) {
TGraph2D* graph = graph2d_it->data_object;
std::string draw_option("A");
draw_option.append(graph2d_it->draw_option);
if (graph) {
graph->Draw(draw_option.c_str());
PadBoundaries current_pad_boundaries(*(TH1*) graph->GetHistogram());
current_pad_boundaries.is_2d = true;
current_pad_boundaries.z_min = graph->GetZmin();
current_pad_boundaries.z_max = graph->GetZmax();
if (nothing_drawn) {
union_pad_boundaries = current_pad_boundaries;
nothing_drawn = false;
} else {
union_pad_boundaries = union_pad_boundaries.getUnionBoundaries(
current_pad_boundaries);
}
}
}
return union_pad_boundaries;
}
示例6: setTimeDisp
void setTimeDisp(TGraph& g, const Int_t ndiv=510) {
if ( (g.GetHistogram()!=0) &&
(g.GetHistogram()->GetXaxis()!=0) ) {
setTimeDisp(*(g.GetHistogram()),ndiv);
}
}