couet
November 19, 2019, 12:39pm
21
main macro use_cutg.C
:
static TCutG *cutg = new TCutG("cutg",6);
void use_cutg()
{
gROOT->ProcessLine(".x xy.C");
cutg->Draw();
}
sub macro xy.C
defining the cut:
{
cutg->SetVarX("X");
cutg->SetVarY("Y");
cutg->SetTitle("cutg");
cutg->SetFillColor(1);
cutg->SetPoint(0,-2.61572,1.1489);
cutg->SetPoint(1,-0.253134,4.13603);
cutg->SetPoint(2,2.66393,1.5625);
cutg->SetPoint(3,-0.084378,-2.38971);
cutg->SetPoint(4,-2.68804,1.05699);
cutg->SetPoint(5,-2.61572,1.1489);
}
try:
root[0] .x use_cutg.C
It will define the cut in xy.C
and draw it in use_cutg.C
Sandy
November 19, 2019, 12:57pm
23
Is there any way to add a circular cut while filling a 2D: like the following:
TEllipse *ellipse = new TEllipse(180.0,180.0,5.0,5.0,0.0,360.0,0.0);
couet
November 19, 2019, 1:01pm
24
The Cut has to be a TGraph.
You will need to define yourself a circle.
Sandy
November 20, 2019, 7:06am
25
Suppose I have made something like this:
const Double_t tm=0., tmx=TMath::TwoPi();
const Int_t n = 500;
const Double_t st = (tmx-tm)/(n-1);
std::vector<Double_t> xArr(n), yArr(n);
for(Int_t i = 0; i < n; ++i)
{
xArr[i] = 2.0-3.0*sin(tm + i * st);
yArr[i] = 2.0-3.0*cos(tm + i * st);
}
TGraph *gr = new TGraph(n, &xArr[0], &yArr[0]);
Then how to put it together with the previous cut? Like the following?
tree->Draw("Y:X>>sum","cutg && gr"," ");
when I do so, it is giving an error:
Error in TTreeFormula::Compile : Bad numerical expression : “gr”
couet
November 20, 2019, 7:52am
26
{
TCutG *cutg2 = new TCutG();
const Double_t tm=0., tmx=TMath::TwoPi();
const Int_t n = 500;
const Double_t st = (tmx-tm)/(n-1);
for (Int_t i = 0; i < n; ++i) cutg2->SetPoint(i, 2.0-3.0*sin(tm + i * st), 2.0-3.0*cos(tm + i * st));
}
Sandy
November 20, 2019, 8:03am
27
Again it is showing:
Error in TTreeFormula::Compile : Bad numerical expression : “cutg2”
Is it because I am doing without leaf information!!
couet
November 20, 2019, 8:13am
28
Yes you should add SetVArX/Y
Sandy
November 20, 2019, 8:28am
29
I have added.
cutg2->SetVarX(“x”);
cutg2->SetVarY(“y”);
How do I use it in determining ‘r’ (x^2+y^2=r^2)?
couet
November 20, 2019, 8:41am
30
I am not sure I understand your question. The 2nd cut (cutg2) is defined as a circle with the little macro you wrote. You can use this cut on x and y in the Draw command. Seems to me you have all you need ? …
Sandy
November 20, 2019, 8:49am
31
How can I use ‘x’ and ‘y’ tree variable inside cutg2?
TCutG *cutg2 = new TCutG("cutg2",500);
cutg2->SetVarX("x");
cutg2->SetVarY("y");
double r = sqrt(pow(x,2.0)+pow(y,2.0));
How to implement this?? so that I can use leaf information in creating the gate and add it further in a 2D. e.g.
tree->Draw("Y:X>>sum","cutg && cutg2"," ");
couet
November 20, 2019, 9:04am
32
I am not sure it will answer you question but in tree->Draw
you can use expression of the tree variables. For instance;
tree->Draw("sqrt(pow(x,2.0)+pow(y,2.0))", "cutg && cutg2", " ");
Sandy
November 20, 2019, 9:08am
33
I want to put the circular cut (cutg2) which uses “sqrt(pow(x,2.0)+pow(y,2.0))” [where x and y are tree variables] and use this cutg2 while drawing different 2D.
couet
November 20, 2019, 9:23am
35
Expressions of tree variables (in your case the radius of the circle) can also be put directly in the selection field of tree->Draw
. They can also be encapsulated in a TCut
as @Wile_E_Coyote suggested.
Sandy
November 20, 2019, 9:33am
36
That means the small macro for cutg2 is no longer useful in such case where I want to use tree variable in writing an equation inside cutg!
couet
November 20, 2019, 9:41am
37
That’s right. There is several ways (as often with ROOT) to get the result.
Sandy
November 20, 2019, 9:54am
38
Ok…according to the current suggestion, when I do:
tree->Draw(“X:Y>>xy”, “cutg && (TMath::sqrt(TMath::pow((p1-2.0),2.0)+TMath::pow((p2-2.0),2.0))=3.0)”, " ");
(note: p1 and p2 are other two tree variables)
it gives again "Error in TTreeFormula::Compile : Bad numerical expression : “TMath::sqrt(TMath::pow((p1-2.0),2.0)+TMath::pow((p2-2.0),2.0))=3.0"”
"TMath::Abs(TMath::Sqrt(TMath::Power(p1 - 2., 2.) + TMath::Power(p2 - 2., 2.)) - 3.) < 0.1"
couet
November 20, 2019, 10:07am
40
Here is a test with the ntuple produced by hsimple.C
:
TCutG *cutg = new TCutG("cutg",6);
cutg->SetVarX("px");
cutg->SetVarY("py");
cutg->SetTitle("cutg");
cutg->SetFillColor(1);
cutg->SetPoint(0,-2.61572,1.1489);
cutg->SetPoint(1,-0.253134,4.13603);
cutg->SetPoint(2,2.66393,1.5625);
cutg->SetPoint(3,-0.084378,-2.38971);
cutg->SetPoint(4,-2.68804,1.05699);
cutg->SetPoint(5,-2.61572,1.1489);
ntuple->Draw("px:py","cutg && TMath::Abs(TMath::Sqrt(TMath::Power(px - 2., 2.) + TMath::Power(py - 2., 2.)) - 3.) < 0.1", "colz")