I currently have a TTree that contains events, and I would like to draw a histogram with variable and graphical cuts. I am drawing this in the terminal with
where cut0 is a pre-defined graphical cut stored in the same TFile as the TTree, and theta is a branch in my TTree. I have noticed that swapping the order of the cuts,
changes the number of counts I get in my final histogram, as well as the overall shape. I would have thought that applying the cuts in a particular order would not matter. Is there a difference between these two options?
does not seem to work (ROOT spits out a load of errors that says I’m misusing the function Draw()). cut0 itself is a TCutG*. This code also does not work when it is cast to a TCut*.
which are clearly different. Could it be a problem in the way one of the quantities is defined? I also have noticed that the cut is not a part of the tree - could that be a potential cause?
I have been using terminal commands, so there is no macro at the moment. The commands I have been using are listed above. The file is too big to share here, but here is a link.
I can reproduce the problem with the following macro:
{
auto f = new TFile("ptmac.root");
auto C = new TCanvas();
C->Divide(2,1);
TCutG *cutg = new TCutG("CUTG",4);
cutg->SetVarX("z");
cutg->SetVarY("theta");
cutg->SetPoint(0,-30,2);
cutg->SetPoint(1,-10,5);
cutg->SetPoint(2,-5,40);
cutg->SetPoint(3,-50,25);
C->cd(1); tree->Draw("z","z>-20 && CUTG");
C->cd(2); tree->Draw("z","CUTG && z>-20");
}
root [3] tree->Scan("z:theta")
***********************************************
* Row * Instance * z * theta *
***********************************************
* 0 * 0 * nan * nan *
* 0 * 1 * nan * nan *
* 0 * 2 * nan * nan *
* 0 * 3 * nan * nan *
* 0 * 4 * nan * nan *
* 0 * 5 * nan * nan *
* 0 * 6 * -45.69178 * nan *
* 0 * 7 * nan * nan *
* 0 * 8 * nan * nan *
* 0 * 9 * nan * nan *
* 0 * 10 * nan * nan *
* 0 * 11 * nan * nan *
* 0 * 12 * nan * nan *
* 0 * 13 * nan * nan *
* 0 * 14 * nan * nan *
* 0 * 15 * nan * nan *
* 0 * 16 * nan * nan *
* 0 * 17 * nan * nan *
* 0 * 18 * nan * nan *
* 0 * 19 * nan * nan *
* 0 * 20 * nan * nan *
* 0 * 21 * nan * nan *
* 0 * 22 * nan * nan *
* 0 * 23 * nan * nan *
The tree is full of NaN when there is no value recorded for a given event. This means that when a certain element of my experiment is triggered, values are not recorded on every element - do you think that this is the source of the problem?
However, I don’t want to do any computation on elements that are not being triggered in an event - if a NaN is not suitable for this, what would you recommend?
Actually, this is not the first time we meet it and I’m sure not the last one. @Axel Maybe one could add “isnan”, “isfinite”, “isinf”, “isnormal” to functions which are recognized in cuts (actually in any TFormula, I think).
Note: “TMath::IsNaN” already exists so one should be able to use it right away in any cuts, e.g.:
As you can see the selection z>-20 and CUTG used separately give the same output. but when I use both ie: z>-20 && CUTG then only one event shows up. That’s wrong obviously … I have no answer yet. When you invert the selection (CUTG first) then the 2 events show up …
The documentation says that the first and last points should be the same, i.e. a closed polygon. Could this be the issue in your example (I can’t test it at the moment)? maybe also in the original problem?
No it is not the problem. Just to be sure I tried with:
{
auto file = new TFile("ptmac.root");
TCutG *gcut = new TCutG("CUTG",5);
gcut->SetVarX("z");
gcut->SetVarY("theta");
gcut->SetPoint(0,-30,2);
gcut->SetPoint(1,-10,5);
gcut->SetPoint(2,-5,40);
gcut->SetPoint(3,-50,25);
gcut->SetPoint(4,-30,2);
int f = 3;
int n = 18-f;
tree->Scan("z:theta","z>-20","",15,3);
tree->Scan("z:theta","CUTG","",15,3);
tree->Scan("z:theta","z>-20 && CUTG","",15,3);
}
Actually I put some debug print out juste before the call to the method deciding whether the point is inside the cut or not (IsInside). The point (xcut,ycut) is passed to this method. and as you can this yciut is wrong (-10000 instead of 26.818965). The the cut it self if fine but the point passed to it is wrong.