# Square within a Square/TCutG

Is it possible with or without TCutG to create a Square of points within another square of points?

The goal is to have an inner square and outer square.

The inner square would operate/look at the data within the inner square.

The outer square would operate/look at the data within the square minus the area within the inner square.

``````-----------------------------|
|                                  |
|                                  |
|   _____________     |
|   |                        |     |
|   |                        |     |
|   ---------------------     |
|                                 |
----------------------------
``````

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

A TCutG is a TGraph and is one set of point. You can try something like that:

``````{
Double_t X1[14] = { 0.4, 0.4, 0.2, 0.2, 0.7, 0.7, 0.4, 0.4, 0.6, 0.6, 0.3, 0.3, 0.4, 0.4};
Double_t Y1[14] = { 0.5, 0.7, 0.7, 0.15, 0.15, 0.7, 0.7, 0.5, 0.5, 0.2, 0.2, 0.5, 0.5, 0.7};
TGraph *graph = new TGraph(14,X1,Y1);
graph->Draw("al");
}
``````

Olivier,

Thank you for the response.

I know TCutG is a derived class of TGraph. Which is good.

Iâ€™ve taken the liberty to add the root.exe commands that creates a canvas, a 2d Double histogram, fills the histogram, and then a TCutG region. See below:

{

// Creates a Canvas to perform operations on with an X/y dimention of

// 500 x 500.

TCanvas *c2 = new TCanvas(â€śc2â€ť, â€śmy 2d plotâ€ť, 500, 500);

// Creates a 2D Histogram object with a 100 bin x and 100 bin y.

// the range will be x [-5, 5], y [-5, 5]

//

TH2D *htwoD = new TH2D(â€śhtwoDâ€ť, â€śA 2D histogramâ€ť, 100, -5, 5, 100, -5, 5)

// A for loop to randomly poplulate the histogram.

// Here you have 2 histograms.

// the loop is 10,000 because of the 100x100 x/y bins set above.

for (int i = 0; i< 100000; i++) {htwoD->Fill(gRandom->Gaus(-0.5, 0.1), gRandom->Gaus(-0.5, 0.1));htwoD->Fill(gRandom->Gaus(0.2, 0.2), gRandom->Gaus(1.4, 0.2)); }

// Draw histogram data points in colors (colz)

htwoD->Draw(â€ścolzâ€ť);

// Specify the X/Y tuplets for the TCutG

// rectangle

double x1[] = {0.5, 1.25, -1, -1.25, .5};

double y[] = {-1, 1, 1.75, 0, -1};

// Crete a 5 point TCutG region.

TCutG *cutg = new TCutG(â€śmycutâ€ť,5, x1, y);

cutg->SetVarX(â€śxâ€ť);

cutg->SetVarY(â€śyâ€ť);

cutg->Draw()

}

The output looks like:

Now here is my rephrased question.

My TCutG1 region shown has data points from both random data points. I can pass this to my fpga and it knows what to do.

My problemâ€¦ How can I crate another TCutG2 region that encapsulates everything except what my TCutG1 region encapsulates?

Thank you,

Angel

When you draw an histogram with a cut you cannot combine cuts, nor do any boolean expression. One way to do what you want is by defining one cut as I explained before.

``````{
TCanvas *c2 = new TCanvas("c2", "my 2d plot", 500, 500);

TH2D *htwoD = new TH2D("htwoD", "A 2D histogram", 100, -5, 5, 100, -5, 5);

for (int i = 0; i< 100000; i++) {
htwoD->Fill(gRandom->Gaus(-0.5, 0.1), gRandom->Gaus(-0.5, 0.1));
htwoD->Fill(gRandom->Gaus(0.2, 0.2), gRandom->Gaus(1.4, 0.2));
}

double X1[] = {0.5, 1.25,   -1, -1.25,    -0.5,-0.75,0.5,2.,-1.5,-1.9,-0.75,-0.5};
double Y1[] = {-1 , 1   , 1.75,     0,    -0.4,-1.,-1.7,1.9,3.,-0.6,-1.,-0.4,0.};

TCutG *cutg = new TCutG("mycut",12, X1, Y1);
htwoD->Draw("colz [mycut]");
cutg->Draw("l");
}
``````

``````void tp()
{
TCanvas *c2 = new TCanvas("c2", "c2", 1000, 524);
c2->Divide(2,1);
auto hinner = new TH2F("hinner", "hinner", 50,-25, 25, 25, -25, 25);
auto houter = new TH2F("houter", "houter", 50,-25, 25, 25, -25, 25);

Double_t sxinner[5]={-5, 5, 5, -5, -5};
Double_t syinner[5]={-5, -5, 5, 5, -5};

Double_t sxouter[5]={-15, 15, 15, -15, -15};
Double_t syouter[5]={-15, -15, 15, 15, -15};

auto cinner = new TCutG("cinner", 5, sxinner, syinner);
auto couter = new TCutG("couter", 5, sxouter, syouter);

Int_t n = 1000000;
while (n--  > 0) {
Double_t x = 50.*gRandom->Rndm()-25.;
Double_t y = 50.*gRandom->Rndm()-25.;
if (cinner->IsInside(x,y)) {
hinner->Fill(x,y);
} else if ( couter->IsInside(x,y)) {
houter->Fill(x,y);
}
}
c2->cd(1);
hinner->Draw("colz");
c2->cd(2);
houter->Draw("colz");
}
``````

Otto

1 Like

Otto,

Thank you very much for your suggestions and help!

Regards,

Angel

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.