Prevent user from rotating a histogram

Hi all,

is there a way to prevent the user from mouse-rotating a 2D histogram (one that is plotted in a 3d style, such as LEGO)? I would expect something like TH1::SetBit(kCannotPick), but I couldn’t find anything like that…
Thanks!

Thomas

Hi Thomas,

gPad->SetEditable(kFALSE);Jan

Thanks for the suggestion! This works, but is rather general (I have to make sure gPad is set back to editable whenever I plot something else on the same canvas, where the editing is desired). It would be nice if the histogram had a property that I could set, and then I would only affect that one histogram. Apparently it does not exist…

h2->Draw("lego"); gPad->GetView()->SetBit(2048, 0); // rotate on gPad->GetView()->SetBit(2048, 1); // rotate off
for more info see in: root.cern.ch/root/htmldoc/src/TH … r.cxx.html

I hope this help, Jan

Hi Jan,

thanks again. This looks like what I want, but I can’t get it to work.
Consider the following macro:

void testSetBit() { TCanvas *c1 = new TCanvas("c1","c1",800,800); TH2D *h = new TH2D("h","h",40,-4,4,40,-4,4); Double_t a,b; for (Int_t i=0;i<10000;i++) {gRandom->Rannor(a,b);h->Fill(a-1.5,b-1.5);} h->Draw("lego"); // gPad->GetView()->SetBit(2048, 0); // rotate on gPad->GetView()->SetBit(2048, 1); // rotate off }

“rotate on” or “rotate off” makes no difference for me (5.18.00). What am I doing wrong?

Thomas

I think problem is in “BIT(11) function” (different platform/system), please try the executing script via ACLiC:[code]#include <TCanvas.h>
#include <TH2.h>
#include <TRandom.h>
#include <TView.h>

void testSetBit()
{
TCanvas *c1 = new TCanvas(“c1”,“c1”,800,800);
TH2D *h = new TH2D(“h”,“h”,40,-4,4,40,-4,4);
Double_t a,b;
for (Int_t i=0;i<10000;i++) {gRandom->Rannor(a,b);h->Fill(a-1.5,b-1.5);}
h->Draw(“lego”);
c1->Update();

UInt_t bit11 = BIT(11);
Printf(“BIT(11) on my system = %d”, bit11);
// gPad->GetView()->SetBit(bit11, 0); // rotate on
gPad->GetView()->SetBit(bit11, 1); // rotate off
}[/code][quote]root [0] .x testSetBit.C+
root [1] BIT(11) on my system = 2048 [/quote]
Jan

Your macro gives me:

[quote]root [0] .x testSetBit.C
Error: Function BIT(11) is not defined in current scope testSetBit.C:63:
*** Interpreter error recovered ***
root [1] [/quote]

I have tried with all the #includes THistPainter.cxx has, without success.
In fact,

yields

[quote]Error: Function BIT(11) is not defined in current scope (tmpfile):1:
*** Interpreter error recovered ***[/quote]

in every ROOT session I have tried. How can THistPainter define

without trouble? I get more and more confused…

Thomas

Ooops, sorry, I overlooked your mentioning ACLiC,… I will try with that!

OK, when I compile the code, BIT(11) indeed evaluates to 2048, but I still don’t see an effect. My program now reads

[code]// To compile:
// g++ testSetBit.C -o testSetBit root-config --cflags --libs
// To execute:
// ./testSetBit 0 or ./testSetBit 1

#include <TApplication.h>
#include <TCanvas.h>
#include <TH2.h>
#include <TRandom.h>
#include <TView.h>

int main(int argc, char *argv)
{
TApplication theApp(“App”,&argc,argv);
Int_t rotOpt = 0;
char
opt;
if (argc==2) {
opt = argv[1];
rotOpt = TString(opt).Atoi();
}
TCanvas *c1 = new TCanvas(“c1”,“c1”,800,800);
TH2D *h = new TH2D(“h”,“h”,40,-4,4,40,-4,4);
Double_t a,b;
for (Int_t i=0;i<10000;i++) {gRandom->Rannor(a,b);h->Fill(a-1.5,b-1.5);}
h->Draw(“lego”);
c1->Update();
UInt_t bit11 = BIT(11);
Printf(“BIT(11) on my system = %d”, bit11);
Printf(“rotate option is = %d”, rotOpt);
gPad->GetView()->SetBit(bit11, rotOpt);
theApp.Run();
return(0);
}[/code]

I compile it and run it as stated in the comment. 0 or 1 still make no difference…

Thomas