#include "iostream.h" #include "TObject.h" #include "TString.h" #include "TTree.h" #include "TFile.h" #include "TTree.h" #include "TGraph.h" #include "TGraphErrors.h" #include "TLatex.h" void Superimpose_rates(){ // // Example showing how to superimpose a TGraph with a different range // using a transparent pad. // gROOT->Reset(); c1 = new TCanvas("c1","EffGain_Rates",200,10,700,500); TPad *pad = new TPad("pad","",0,0,1,1); pad->SetGrid(); pad->Draw(); pad->cd(); // create first graph gr1 = new TGraphErrors("Gain2800_1700_1400_300_500.txt"); //gr1->SetTitle("2800_1700_1400_300_500"); gr1->SetMarkerColor(kBlue); gr1->SetMarkerStyle(21); gr1->GetYaxis()->SetLabelColor(kBlue); gr1->GetYaxis()->SetTitle("Effective Gain"); // gr1->GetYaxis()->SetTitlelColor(kBlue); gr1->GetYaxis()->SetTitleOffset(1.5); //Set YTitle Offset 20% more than the standard one gr1->Draw("AP"); // create second graph //create a transparent pad drawn on top of the main pad c1->cd(); TPad *overlay = new TPad("overlay","",0,0,1,1); //compute the pad range with suitable margins Double_t ymin = 0; Double_t ymax = 2000; Double_t dy = (ymax-ymin)/0.8; //10 per cent margins top and bottom Double_t xmin = -3; Double_t xmax = 3; Double_t dx = (xmax-xmin)/0.8; //10 per cent margins left and right overlay->Range(xmin-0.1*dx,ymin-0.1*dy,xmax+0.1*dx,ymax+0.1*dy); overlay->SetFillStyle(4000);// will be transparent overlay->SetFillColor(0); overlay->SetFrameFillStyle(4000); overlay->Draw(); overlay->cd(); gr2 = new TGraphErrors("Rates2800_1700_1400_300_500.txt"); gr2->GetYaxis()->SetLabelOffset(999); gr2->GetYaxis()->SetTickLength(0); gr2->GetXaxis()->SetTitle("Drift Voltage [V]"); gr2->GetXaxis()->CenterTitle(); gr2->SetMarkerColor(kRed); gr2->SetMarkerStyle(20); gr2->SetName("gr2"); gr2->Draw("AP"); overlay->Update(); // Draw an axis on the right side TGaxis *axis = new TGaxis(2740,ymin,2740, ymax,ymin,ymax,51010,"+S",0.03); axis->SetLabelOffset(0.05); axis->SetLineColor(kRed); axis->SetLabelColor(kRed); axis->SetTickLength(0.01); axis->SetLabelSize(0.03); axis->SetTitle("Rates [Hz]"); axis->Draw(); }