Hi,
I guess this issue is solved on my side. I just wanted to expand this old post:
If I do:
THStack* hs = blah;
hs->Add(…);
Then If I want to edit the y-axis and draw:
hs->SetMaximum(600);
hs->Draw();
As the previous post says the result is not 600, but slightly more based on ‘gStyle->GetHistTopMargin()’. But if one draws the stack in log mode, they must be weary of what is being done behind the scenes:
root.cern.ch/root/html/src/THStack.cxx.html#717
and
root.cern.ch/root/html/src/THStack.cxx.html#722
Thus to get my proper y-axis I need to do this:
if(!gPad->GetLogy()){
stack->SetMaximum(themax/(1+gStyle->GetHistTopMargin()));
stack->SetMinimum(themin);
}
else {//I know exactly what I want my hist range to be
stack->SetMaximum(themax/(1+0.2TMath::Log10(themax/themin)));
stack->SetMinimum(themin(1+0.5*TMath::Log10(themax/themin)));
}
I understand the need to make sure that the user defined gStyle is adhered to, but why do I have to go through so much trouble just to set the min and max in log mode? I think that if I explicitly tell my stack to have a certain maximum, I expect it to be followed. I save my canvas as a root file. Open the canvas in a TBrowser and manually set the axis range through the GUI, I then want to put these values in my script so that the next time I run the script, I can just directly extract an eps or whatever. I spent a whole morning trying to figure out exactly what I needed to do to change the y-axis to be exactly what i wanted. I did the old trick of editing the canvas in the GUI, saving as ‘.C’ and inspecting. This is where I discoved that the axis ranges are defined by the THStack::fHistogram. However, I could not figure out how to edit this guy in my macro:
stack->Draw();//ensure that fHistogram exists
stack->GetHistogram()->SetAxisRange(…);
stack->GetYaxis()->SetRangeUser(…);
…
many more desperation attempts that all compile and run–just gives me nothing.
So unless I missed a much simpler method, could documentation be improved?:
root.cern.ch/root/html/THStack.h … SetMaximum
give a warning that the values you insert will be changed?
Or give a method that will actually just do what you ask? If the user gives a negative value for the min or max, then they should be punished… just my opinion.
Thanks,
Justin