rafopar
February 15, 2016, 11:55pm
1
HI,
I have root 6.04/02, Ubuntu 15.04
I specify title offset, then for example if I call some other methods of TF1, for
example SetRange(a, b); or SetTitle(“blabla”);
it doesn’t work, however, if I specify title offset just before draw it works.
My code is below.
void Draw_FSD_Threshold()
{
TCanvas *c1 = new TCanvas("c1", "", 750, 750);
c1->SetLeftMargin(0.12);
c1->SetGridx(1);
c1->SetGridy(1);
c1->SetLogy();
TF1 *f_erfc = new TF1("f_erfc", "0.5*3.6e6*TMath::Erfc(x/sqrt(2.))", 0., 8.);
f_erfc->SetTitle(" 0.5 #upoint 3.6 #times 10^{6} #upoint ERFC(#sigma/#sqrt{2}); #sigma; N trips/hour");
f_erfc->GetYaxis()->SetTitleOffset(1.5);
f_erfc->SetRange(3., 7.);
f_erfc->Draw();
c1->Print("Accid_trip_rate.eps");
c1->Print("Accid_trip_rate.pdf");
c1->Print("Accid_trip_rate.png");
c1->Clear();
}
Another thing also I noticed, when I do DrawCopy of a same function but with different parameters,
it again doesn’t put correct title offset work
Reverse the order (not sure why it is required):
f_erfc->SetRange(3., 7.);
f_erfc->GetYaxis()->SetTitleOffset(1.5);
rafopar
February 23, 2016, 8:52pm
3
[quote=“Pepe Le Pew”]Reverse the order (not sure why it is required):
f_erfc->SetRange(3., 7.);
f_erfc->GetYaxis()->SetTitleOffset(1.5);[/quote]
Thanks.
Do you have a comment about DrawCopy case.
In this case, I set the range just before the “DrawCopy”, but no effect
TF1 *f_FSD_threshold = new TF1("f_FSD_threshold", "([0]*x*1.e-3 + [1]*sqrt([0]*x*1.e-3))/1.e-3", 6.e4, 6.e5);
f_FSD_threshold->SetTitle("; Stable rates on HPS halo counters [Hz]; Proposed FSD threshold [Hz]");
f_FSD_threshold->SetNpx(4500);
f_FSD_threshold->SetMaximum(1.2e6);
for(int i = 0; i < n_toler; i++ ){
f_FSD_threshold->SetParameters(tolerance_[i], 5.5);
f_FSD_threshold->SetLineColor(i+1);
f_FSD_threshold->GetYaxis()->SetTitleOffset(1.6);
if( i == 0 ){ f_FSD_threshold->DrawCopy();}
else {f_FSD_threshold->DrawCopy("Same");}
lat1->SetTextColor(i+1);
lat1->DrawLatex(0.15, 0.65 + 0.05*double(i), Form("%d %% above av. rates", int(100*(tolerance_[i] - 1)) ));
}
couet
February 24, 2016, 9:36am
4
When I change Draw() to DrawCopy() in your 1st modified macro, I get the same plot as when Draw() was used:
void Draw_FSD_Threshold()
{
TCanvas *c1 = new TCanvas("c1", "", 750, 750);
c1->SetLeftMargin(0.12);
c1->SetGridx(1);
c1->SetGridy(1);
c1->SetLogy();
TF1 *f_erfc = new TF1("f_erfc", "0.5*3.6e6*TMath::Erfc(x/sqrt(2.))", 0., 8.);
f_erfc->SetTitle(" 0.5 #upoint 3.6 #times 10^{6} #upoint ERFC(#sigma/#sqrt{2}); #sigma; N trips/hour");
f_erfc->SetRange(3., 7.);
f_erfc->GetYaxis()->SetTitleOffset(1.5);
f_erfc->DrawCopy();
}
rafopar
February 24, 2016, 2:02pm
5
Sorry, if I was not clear.
there were two issues, First was with Draw(),
when I specify SetRange before before set title,.
the second issue is, when I need to Draw same function on top of each other, but
just changing the parameters. For that I need to use DrawCopy(), but
as I used DrawCopy, The Y title offset again doesn’t change.
So this is my complete code. it produces two figures, the Y title offset of the 2nd
is not at the right place.
Thank You!
#include <TF1.h>
#include <TH1D.h>
#include <TH2D.h>
#include <TLatex.h>
#include <TCanvas.h>
void Draw_FSD_Threshold()
{
TLatex *lat1 = new TLatex();
lat1->SetNDC();
TCanvas *c1 = new TCanvas("c1", "", 750, 750);
c1->SetLeftMargin(0.12);
c1->SetGridx(1);
c1->SetGridy(1);
c1->SetLogy();
TF1 *f_erfc = new TF1("f_erfc", "0.5*3.6e6*TMath::Erfc(x/sqrt(2.))", 0., 8.);
f_erfc->SetTitle(" 0.5 #upoint 3.6 #times 10^{6} #upoint ERFC((thr-MPV)/(#sigma #sqrt{2})); (thr-MPV)/#sigma; N trips/hour");
f_erfc->SetRange(3., 7.);
f_erfc->GetYaxis()->SetTitleOffset(1.5);
f_erfc->Draw();
c1->Print("Accid_trip_rate.eps");
c1->Print("Accid_trip_rate.pdf");
c1->Print("Accid_trip_rate.png");
c1->Clear();
const int n_toler = 3;
double tolerance_[n_toler] = {1., 1.3, 1.6};
c1->SetLogy(0);
TF1 *f_FSD_threshold = new TF1("f_FSD_threshold", "([0]*x*1.e-3 + [1]*sqrt([0]*x*1.e-3))/1.e-3", 6.e4, 6.e5);
f_FSD_threshold->SetTitle("; Stable rates on HPS halo counters [Hz]; Proposed FSD threshold [Hz]");
f_FSD_threshold->SetNpx(4500);
f_FSD_threshold->SetMaximum(1.2e6);
for(int i = 0; i < n_toler; i++ ){
f_FSD_threshold->SetParameters(tolerance_[i], 5.5);
f_FSD_threshold->SetLineColor(i+1);
f_FSD_threshold->GetYaxis()->SetTitleOffset(1.6);
if( i == 0 ){ f_FSD_threshold->DrawCopy();}
else {f_FSD_threshold->DrawCopy("Same");}
lat1->SetTextColor(i+1);
lat1->DrawLatex(0.15, 0.65 + 0.05*double(i), Form("%d %% above av. rates", int(100*(tolerance_[i] - 1)) ));
}
c1->Print("FSD_Thresholds_5p5sigma.eps");
c1->Print("FSD_Thresholds_5p5sigma.pdf");
c1->Print("FSD_Thresholds_5p5sigma.png");
Try (not sure why it is required):
if(!i) { f_FSD_threshold->DrawCopy()->GetYaxis()->SetTitleOffset(1.6); }
else { f_FSD_threshold->DrawCopy(“SAME”); }