本文整理汇总了C++中TH1::GetXaxis方法的典型用法代码示例。如果您正苦于以下问题:C++ TH1::GetXaxis方法的具体用法?C++ TH1::GetXaxis怎么用?C++ TH1::GetXaxis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TH1
的用法示例。
在下文中一共展示了TH1::GetXaxis方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getPlotData
void getPlotData() {
TH1 * h = (TH1*) m_file->Get(m_direc.c_str());
for (int i=0; i<h->GetXaxis()->GetNbins(); i++) {
m_xs.push_back(h->GetXaxis()->GetBinCenter(i));
m_ys.push_back(h->GetBinContent(i));
}
m_plot->m_xAxisTitle = std::string(h->GetXaxis()->GetTitle());
m_plot->m_yAxisTitle = std::string(h->GetYaxis()->GetTitle());
m_plot->m_title = std::string(h->GetTitle());
std::stringstream ssN, ssMu, ssSig, ssUF, ssOF;
ssN << std::setprecision(4) << h->GetEntries();
ssMu << std::setprecision(4) << h->GetMean();
ssSig << std::setprecision(4) << h->GetRMS();
ssUF << std::setprecision(4) << h->GetBinContent(0);
ssOF << std::setprecision(4) << h->GetBinContent(h->GetNbinsX() + 1);
m_statsTitles.push_back("N:");
m_statsTitles.push_back("mu:");
m_statsTitles.push_back("sig:");
m_statsTitles.push_back("UF:");
m_statsTitles.push_back("OF:");
m_statsValues.push_back(ssN.str());
m_statsValues.push_back(ssMu.str());
m_statsValues.push_back(ssSig.str());
m_statsValues.push_back(ssUF.str());
m_statsValues.push_back(ssOF.str());
}
示例2: UpdateHist
// show the histogram in first slot, try a Gaussian fit with given parameters
void PRadHistCanvas::UpdateHist(int index, TObject *tob, int range_min, int range_max)
{
--index;
if(index < 0 || index >= canvases.size())
return;
canvases[index]->cd();
canvases[index]->SetGrid();
gPad->SetLogy();
TH1 *hist = (TH1*)tob;
hist->GetXaxis()->SetRangeUser(hist->FindFirstBinAbove(0,1) - 10,
hist->FindLastBinAbove(0,1) + 10);
hist->GetXaxis()->SetLabelSize(HIST_LABEL_SIZE);
hist->GetYaxis()->SetLabelSize(HIST_LABEL_SIZE);
// try to fit gaussian in certain range
if(range_max > range_min
&& hist->Integral(range_min, range_max + 1) > 0)
{
TF1 *fit = new TF1("", "gaus", range_min, range_max);
fit->SetLineColor(kRed);
fit->SetLineWidth(2);
hist->Fit(fit,"qlR");
}
hist->SetFillColor(fillColors[index]);
hist->Draw();
canvases[index]->Refresh();
}
示例3: SetTitle
void SetTitle(TH1& h, TString Xtitle, TString Ytitle, TString title){
h.GetXaxis()->SetTitle(Xtitle);
h.GetYaxis()->SetTitle(Ytitle);
h.GetXaxis()->CenterTitle();
h.GetYaxis()->CenterTitle();
h.SetTitle(title);
}
示例4: FillCollection
//_________________________________________________________________________________________________
void FillCollection(AliMergeableCollection& hc, time_t runStart, time_t runEnd, int timeResolution)
{
TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
AliMpBusPatch* bp;
Double_t xmin = runStart*1.0;
Double_t xmax = runEnd*1.0;
int nbins = TMath::Nint((runEnd-runStart)/timeResolution);
// basis for all plot = per buspatch
while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
{
TH1* h = new TH1F(Form("BP%04d",bp->GetId()),Form("Number of hits in %d s bins",timeResolution),nbins,xmin,xmax);
h->GetXaxis()->SetTimeDisplay(1);
h->GetXaxis()->SetTimeFormat("%H:%M");
hc.Adopt(Form("/BUSPATCH/HITS/%ds",timeResolution),h);
}
nbins = TMath::Nint((runEnd-runStart)/timeResolution);
// number of events needed for normalization
TH1* h = new TH1F(Form("Nevents%ds",timeResolution),Form("Number of events %d s bins",timeResolution),nbins,xmin,xmax);
h->GetXaxis()->SetTimeDisplay(1);
h->GetXaxis()->SetTimeFormat("%H:%M");
hc.Adopt("",h);
}
示例5: getHisto
// -----------------------------------------------------------------------------
//
TH1* getHisto( std::string nameFile,
std::string nameHist,
std::string Dirname,
int rebin ) {
std::string name = nameFile;
TFile* file = new TFile(name.c_str());
if (file) { std::cout << "Opened file: " << file->GetName() << std::endl; }
else {
std::cout << "Could not find file: " << name << std::endl;
return 0;
}
TDirectory* dir = (TDirectory*)file->Get(Dirname.c_str());
if (dir) { std::cout << "Opened dir: " << dir->GetName() << std::endl; }
else {
std::cout << "Could not find dir: " << Dirname << std::endl;
return 0;
}
int low = 375;
TH1* hist = 0;
if ( false || nameHist.find("HtMultiplicity_HT375") == std::string::npos ) {
hist = (TH1*)dir->Get(nameHist.c_str());
} else {
for ( uint ii = low; ii <= 975; ii+=100 ) {
std::stringstream tmp; tmp << "HtMultiplicity_HT" << ii << nameHist.substr(20);
if ( !hist ) {
dir->cd();
TH1D* temp = (TH1D*)dir->Get( "HtMultiplicity_HT375_aT0" );
//TH1D* temp = (TH1D*)file->Get( tmp.str().c_str() );
if (temp) { hist = (TH1D*)temp->Clone(); }
else { std::cout << "1 Unable to retrieve histo with name " << tmp.str() << std::endl; }
} else {
dir->cd();
TH1D* temp = (TH1D*)dir->Get( tmp.str().c_str() );
if (temp) { hist->Add( (TH1D*)temp ); }
else { std::cout << "2 Unable to retrieve histo with name " << tmp.str() << std::endl; }
}
}
}
if (hist) { std::cout << "Opened histo: " << hist->GetName() << std::endl; }
else {
std::cout << "Could not find histo: " << nameHist << std::endl;
return 0;
}
hist->SetLineWidth(3);
if ( rebin > 0 ) { hist->Rebin(rebin); }
hist->GetXaxis()->SetTitleSize(0.055);
hist->GetYaxis()->SetTitleSize(0.055);
hist->GetXaxis()->SetLabelSize(0.05);
hist->GetYaxis()->SetLabelSize(0.05);
hist->SetStats(kFALSE);
return hist;
}
示例6: Run
//____________________________________________________________________
void Run(const char* newName, const char* oldName,
const char* newTitle="New", const char* oldTitle="Old")
{
TFile* newFile = TFile::Open(newName,"READ");
TFile* oldFile = TFile::Open(oldName,"READ");
if (!newFile || !oldFile) return;
TH1* newCent = GetH1(newFile, "realCent");
TH1* oldCent = GetH1(oldFile, "realCent");
if (!newCent || !oldCent) return;
TString t; t.Form("#it{R}=#frac{%s}{%s}", newTitle, oldTitle);
TCanvas* c = new TCanvas("c", t, 1200, 800);
c->SetTopMargin(0.01);
c->SetRightMargin(0.20);
fLegend = new TLegend(1-c->GetRightMargin(),
c->GetBottomMargin(),
1, 1-c->GetTopMargin(),
t);
fLegend->SetFillStyle(0);
fLegend->SetBorderSize(0);
THStack* stack = new THStack("ratios","");
fMin = +1e6;
fMax = -1e6;
TH1* one = 0;
for (Int_t i = newCent->GetNbinsX(); i--;) {
Double_t c1 = newCent->GetXaxis()->GetBinLowEdge(i+1);
Double_t c2 = newCent->GetXaxis()->GetBinUpEdge(i+1);
Info("", "c1=%f c2=%f", c1, c2);
TH1* r = One(newFile, oldFile, c1, c2);
if (!r) continue;
if (!one) {
one = static_cast<TH1*>(r->Clone("one"));
one->SetDirectory(0);
one->Reset();
for (Int_t j = 1; j <= one->GetNbinsX(); j++) {
one->SetBinContent(j,1);
one->SetBinError (j,0);
}
}
// r->Add(one, i-1);
// r->Scale(TMath::Power(10,i));
stack->Add(r);
}
stack->Draw("nostack");
stack->SetMinimum(0.95*fMin);
stack->SetMaximum(1.05*fMax);
stack->GetHistogram()->SetXTitle("#eta");
stack->GetHistogram()->SetYTitle("#it{R}");
fLegend->Draw();
c->Modified();
c->Update();
c->cd();
c->SaveAs(Form("%sover%s.png", newTitle, oldTitle));
}
示例7: 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;
}
示例8: ExpandFunctionRange
Bool_t KVCanvas::ExpandFunctionRange()
{
Bool_t up = kFALSE;
TH1* hh = FindHisto();
if (!hh) return up;
TObject* obj = 0;
TIter it(hh->GetListOfFunctions());
while ((obj = it())) {
((TF1*)obj)->SetRange(hh->GetXaxis()->GetXmin(), hh->GetXaxis()->GetXmax());
up = kTRUE;
}
return up;
}
示例9: SetStyle
void SetStyle(TH1& h, double size, int color, int style, int fillstyle=0, int linestyle=1){
h.SetMarkerSize(size);
h.SetMarkerColor(color);
h.SetLineColor(color);
h.SetMarkerStyle(style);
h.SetFillStyle(fillstyle);
h.SetLineStyle(linestyle);
h.GetXaxis()->SetTitleFont(42);
h.GetYaxis()->SetTitleFont(42);
h.GetXaxis()->SetTitleSize(0.048);
h.GetYaxis()->SetTitleSize(0.048);
h.GetXaxis()->CenterTitle();
h.GetYaxis()->CenterTitle();
}
示例10: exec1
// echo object at mouse position
void exec1()
{
//example of macro called when a pad is redrawn
//one must create a TExec object in the following way
// TExec ex("ex",".x exec1.C");
// ex.Draw();
// this macro prints the bin number and the bin content when one clicks
//on the histogram contour of any histogram in a pad
//Author: Rene Brun
if (!gPad) {
Error("exec1", "gPad is null, you are not supposed to run this macro");
return;
}
int event = gPad->GetEvent();
if (event != 11) return;
int px = gPad->GetEventX();
TObject *select = gPad->GetSelected();
if (!select) return;
if (select->InheritsFrom(TH1::Class())) {
TH1 *h = (TH1*)select;
Float_t xx = gPad->AbsPixeltoX(px);
Float_t x = gPad->PadtoX(xx);
Int_t binx = h->GetXaxis()->FindBin(x);
printf("event=%d, hist:%s, bin=%d, content=%f\n",event,h->GetName(),binx,h->GetBinContent(binx));
}
}
示例11: set
histoBook* histoBook::set( string param, string p1, string p2, string p3, string p4 ){
// force the param name to lowercase
transform(param.begin(), param.end(), param.begin(), ::tolower);
TH1* h = get( styling );
if ( h ){
if ( "title" == param ){
h->SetTitle( p1.c_str() );
} else if ( "x" == param ){
h->GetXaxis()->SetTitle( p1.c_str() );
} else if ( "y" == param ){
h->GetYaxis()->SetTitle( p1.c_str() );
} else if ( "legend" == param ){
if ( p2 == "")
p2="lpf";
legend->AddEntry( h, p1.c_str(), p2.c_str() );
legend->Draw();
} else if ( "draw" == param ){
drawOption = p1;
}
}
return this;
}
示例12: if
//________________________________________________________________
void KVCanvas::DynamicZoomTH1(Int_t Sign, Int_t px, Int_t)
{
// Zoom in or out of histogram with mouse wheel
if (!fSelected) return;
TH1* TheHisto = (TH1*) FindHisto();//fSelected;
Double_t percent = 0.15 - Sign * 0.05;
Int_t dX = 0;
px = AbsPixeltoX(px);
TAxis* ax = TheHisto->GetXaxis();
Int_t NbinsXtmp = ax->GetNbins();
Int_t X0tmp = ax->GetFirst();
Int_t X1tmp = ax->GetLast();
Int_t step = TMath::Min(TMath::Max(1, (Int_t)(percent * (X1tmp - X0tmp))), NbinsXtmp / 2);
step *= Sign;
X0tmp = TMath::Min(TMath::Max(X0tmp + step, 1), X1tmp - step);
X1tmp = TMath::Max(TMath::Min(X1tmp - step, NbinsXtmp), X0tmp);
if (X0tmp >= X1tmp) X0tmp = X1tmp - 1;
if (Sign > 0) dX = (Int_t)(X0tmp + (X1tmp - X0tmp) * 0.5 - ax->FindBin(px));
if ((X0tmp - dX) < 0) ax->SetRange(0, X1tmp - X0tmp);
else if ((X1tmp - dX) > ax->GetNbins()) ax->SetRange(ax->GetNbins() - (X1tmp - X0tmp), ax->GetNbins());
else ax->SetRange(X0tmp - dX, X1tmp - dX);
Modified();
Update();
return;
}
示例13: main
int main (int argc, char *argv[])
{
LineStream ls;
char *line;
char *pos;
Stringa buffer;
if (argc != 2) {
usage ("%s <file.intraOffsets>");
}
TH1 *his = new TH1D ("","Intra-read distribution",1000,0,1000);
TCanvas *canv = new TCanvas("","canvas",1200,400);
ls = ls_createFromFile (argv[1]);
while (line = ls_nextLine (ls)) {
his->Fill (atoi (line));
}
ls_destroy (ls);
his->Draw();
his->GetXaxis()->SetLabelSize (0.04);
his->GetYaxis()->SetLabelSize (0.04);
buffer = stringCreate (100);
pos = strchr (argv[1],'.');
if (pos == NULL) {
die ("Expected <file.intraOffsets>: %s",argv[1]);
}
*pos = '\0';
stringPrintf (buffer,"%s_intraDistribution.jpg",argv[1]);
canv->Print (string (buffer),"jpg");
stringDestroy (buffer);
return 0;
}
示例14: 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();
}
}
}
示例15: annconvergencetest
void annconvergencetest( TDirectory *lhdir )
{
TCanvas* c = new TCanvas( "MLPConvergenceTest", "MLP Convergence Test", 150, 0, 600, 580*0.8 );
TH1* estimatorHistTrain = (TH1*)lhdir->Get( "estimatorHistTrain" );
TH1* estimatorHistTest = (TH1*)lhdir->Get( "estimatorHistTest" );
Double_t m1 = estimatorHistTrain->GetMaximum();
Double_t m2 = estimatorHistTest ->GetMaximum();
Double_t max = TMath::Max( m1, m2 );
m1 = estimatorHistTrain->GetMinimum();
m2 = estimatorHistTest ->GetMinimum();
Double_t min = TMath::Min( m1, m2 );
estimatorHistTrain->SetMaximum( max + 0.1*(max - min) );
estimatorHistTrain->SetMinimum( min - 0.1*(max - min) );
estimatorHistTrain->SetLineColor( 2 );
estimatorHistTrain->SetLineWidth( 2 );
estimatorHistTrain->SetTitle( TString("MLP Convergence Test") );
estimatorHistTest->SetLineColor( 4 );
estimatorHistTest->SetLineWidth( 2 );
estimatorHistTrain->GetXaxis()->SetTitle( "Epochs" );
estimatorHistTrain->GetYaxis()->SetTitle( "Estimator" );
estimatorHistTrain->GetXaxis()->SetTitleOffset( 1.20 );
estimatorHistTrain->GetYaxis()->SetTitleOffset( 1.65 );
estimatorHistTrain->Draw();
estimatorHistTest ->Draw("same");
// need a legend
TLegend *legend= new TLegend( 1 - c->GetRightMargin() - 0.45, 1-c->GetTopMargin() - 0.20,
1 - c->GetRightMargin() - 0.05, 1-c->GetTopMargin() - 0.05 );
legend->AddEntry(estimatorHistTrain,"Training Sample","l");
legend->AddEntry(estimatorHistTest,"Test sample","l");
legend->Draw("same");
legend->SetMargin( 0.3 );
c->cd();
TMVAGlob::plot_logo(); // don't understand why this doesn't work ... :-(
c->Update();
TString fname = "plots/annconvergencetest";
TMVAGlob::imgconv( c, fname );
}