TTree Draw() 2D histogram with TCut

I just tried to draw 2D histograms with TCut in command line like:

TH2F *h= new TH2F(“h_foobar”,“h_foobar”,10,0., 600.,10,0.,600.);
TCut tcut = " foo > 600000. && bar > 600000."

this doesn’t work as I want.
Only when “foo” and “bar” are plotted, they must be divided by 1000. , but it seems they are also divided by 1000. in the evaluation of TCut.
i.e. actual cut executed in root is “foo/1000. > 600000. && bar/1000. > 600000.” .

On the other hand, when you draw 1D histogram like:

TH1F *h= new TH1F(“h_foo”,10,0., 600.);
TCut tcut = " foo > 600000."

The problem doesn’t happen.

Is this the true feature of root ?
If so, it is very confusing that drawing rule is different between 1D and 2D histograms.

The root version I use is 5.34/13 .

Weird. I will check…

with the ntuple generate by simple.C I tried:

root [2] TCut tcut = "px/1000>0. && py/1000>0."
(TCut &) @0x118a7d128
root [3] ntuple->Draw("px/1000:py/1000",tcut)
(Long64_t) 6237
root [4] 

I get the correct result.

Thank you for your reply but I’m not sure your code can be the validation.
If the cut become “px/1000./1000.>0 && py /1000./1000. > 0.” or not your TCut make no difference.

[quote=“couet”]with the ntuple generate by simple.C I tried:

root [2] TCut tcut = "px/1000>0. && py/1000>0."
(TCut &) @0x118a7d128
root [3] ntuple->Draw("px/1000:py/1000",tcut)
(Long64_t) 6237
root [4] 

I get the correct result.[/quote]

provide somme example showing the problem please.
Many thanks.

I see no problem with: { TFile *f = TFile::Open("hsimple.root"); TCanvas *c = new TCanvas("c", "c", 900, 600); c->Divide(3, 2); c->cd(1); TCut tcut1 = "1"; std::cout << ntuple->Draw("px/1000:py/1000", tcut1) << std::endl; c->cd(4); TCut tcut2 = "px>0.000001 && py>0.000001"; std::cout << ntuple->Draw("px/1000:py/1000", tcut2) << std::endl; c->cd(2); TCut tcut3 = "px/1000>0.000001 && py/1000>0.000001"; std::cout << ntuple->Draw("px/1000:py/1000",tcut3) << std::endl; c->cd(5); TCut tcut4 = "px/1000.>0.000001 && py/1000.>0.000001"; std::cout << ntuple->Draw("px/1000.:py/1000.",tcut4) << std::endl; c->cd(3); TCut tcut5 = "px/1000/1000>0.000001 && py/1000/1000>0.000001"; std::cout << ntuple->Draw("px/1000:py/1000",tcut5) << std::endl; c->cd(6); TCut tcut6 = "px/1000./1000.>0.000001 && py/1000./1000.>0.000001"; std::cout << ntuple->Draw("px/1000.:py/1000.",tcut6) << std::endl; } which prints (with my “hsimple.root”): 25000 6237 6228 6228 649 649

Sorry but I totally misunderstood the situation.
It doesn’t seem from the TCut.
With removing the variable from TCut the situation is the same.

My code automatically generate TCut and hisgtograms so I can’t upload my codes.
But I can reproduce the situation in command line.

Open the tree which name is “tmva” and

root [17] TCut tcut="(((region>=4)&&(IsNoLepton>=1)&&(30000.<=mT)&&(mT<=100000.)))*(weight)";
root [18] TH1F *h1 = new TH1F(“h1”,“h1”, 10,160.,1160.);
root [19] tmva->Draw(“MET_E/1000.>>h1”,tcut);
This success with the proper distribution.

root [20] TH2F *h = new TH2F(“h”,“h”, 10,160.,1160.,10,1800.,3800.);
root [21] tmva->Draw(“MET_E/1000.:meff/1000.>>h”,tcut);
This fails and all the MET_E are filled in overflow bin.
So it seems the /1000. doesn’t work in my situation

Many thanks.

TH2F *h = new TH2F(“h”, “h”, 10, 1800., 3800., 10, 160., 1160.);
tmva->Draw(“meff/1000.:MET_E/1000.>>h”, tcut);

The exchanged plot also doesn’t work.
The axis for “MET_E” again over flowed.

And this kind of plot works well.

int Macro(){
    TFile *f = TFile::Open("rootfiles/Wmunu_1lepton.root");
    TTree *tt = (TTree*)f->Get("tmva");
    TCut tcut= "(((tmva.region>=4)&&(tmva.IsNoLepton>=1)&&(30000.<=tmva.mT)&&(tmva.mT<=100000.)))";
    TTreeFormula ttf("selec",tcut,tt);
    TTreeFormula ttf_weight("selec", "tmva.weight",tt);
    TTreeFormula ttf_meff("meff","tmva.meff/1000.",tt);
    TTreeFormula ttf_MET_E("MET_E","tmva.MET_E/1000.",tt);
    TH2F *h2 = new TH2F("h","h",10,160.,1160.,10,1800.,3800.);
    long iEntry(0);
            h2->Fill(ttf_MET_E.EvalInstance(), ttf_meff.EvalInstance(),ttf_weight.EvalInstance());
 return 0;

I’m not sure the difference.
I think root do this kind of thing internally…

I guess one would need your “Wmunu_1lepton.root” file in order to reproduce your problem.