void Second_x_axis() { auto canv = new TCanvas("s1","second axis"); canv->SetLogy(); Double_t nBins = 200000; Double_t endPoint = 800000; Double_t beginPoint = 0; TFile *f1 = TFile::Open("data.root"); TH1D *h1 = new TH1D("sim1", "current", nBins, beginPoint, endPoint); TTreeReader myReader1("DataTree", f1); TTreeReaderValue myInjEnergy1(myReader1, "TRAP2"); while (myReader1.Next()) { h1->Fill(*myInjEnergy1);} h1->Draw("HIST L SAME"); h1->SetLineColor(kBlack); Double_t p_0 = 1.21545e-02; Double_t p_1 = 6.48653e-05; // 04-03-2024 auto low_bin = h1->GetXaxis()->GetXmin(); auto up_bin = h1->GetXaxis()->GetXmax(); h1->SetTitle(""); h1->GetXaxis()->Set(nBins, low_bin*p_1+p_0, up_bin*p_1+p_0); //calibrating the x-axis TF1 *func = new TF1("func","(x - [0])/[1]",0,endPoint); //reverse calibration to get the bin numbers again. func->SetParameters(p_0,p_1); TGaxis *axis = new TGaxis(gPad->GetUxmin() ,gPad->GetUymax(), gPad->GetUxmax(), gPad->GetUymax(),beginPoint ,endPoint, 10, "-"); //drawing the Gaxis using the user coordinates axis->Draw("same"); axis->SetTitle("Channels"); axis->CenterTitle(true); h1->SetStats(0); h1->GetXaxis()->SetTitle("Energy [MeV]"); h1->GetXaxis()->CenterTitle(true); h1->GetYaxis()->SetTitle("Counts"); h1->GetYaxis()->CenterTitle(true); canv->Update(); }