# How to create borders around different areas overlapping in several 2D histograms

I have several 2D histograms that output a box-like area with the same axes scales with some overlap. I have used THStack to plot them in the same canvas by using the option “NOSTACKCOLZ” to demonstrate that they are overlapping…however there is no way to distinguish them from one another using this option.

I would like to separate them by outlining the border, or cuts I applied to each of the areas, on the THStack histogram (as they are separate histograms stored in the rootfile). What is the best way to do this? I have tried to define lines within the looping of filling histograms but it is not working.

Below is my code. Would appreciate any help!!!

Thank you!!

``````  Int_t binx = 7;
Int_t biny = 7;
//defining limits slopes etc
for (Int_t xx=0;xx<binx;xx++){
xc_low[xx]=-21.+33.*xx/(binx+1);
xc_high[xx]=xc_low[xx]+2*33./(binx+1);
}

for (Int_t yy=0;yy<biny;yy++){
yc_low[yy]=-20.+40.*yy/(biny+1);
yc_high[yy]=yc_low[yy]+2*40./(biny+1);
}

//create 49 histograms for 49 overlapping areas
for (Int_t j=0;j<binx*biny;j++){
histXC1YC1[j] = new TH2F(Form("histXC1YC1_%d",j),Form("histXC1YC1_%d",j),50,-24.0,14.0,50,-24.0,24.0);
}
//create stack
THStack *h = new THStack("h","combo calo areas");
//loop and plot cut areas
for (Int_t nx=0;nx<binx;nx++){
//defining lines to create "border" around each area
TF1 *f1 = new TF1("f1",Form("%f",xc_high[nx]),0,10);
f1->SetLineColor(4);
TF1 *f2 = new TF1("f2",Form("%f",xc_low[nx]),0,10);
f2->SetLineColor(4);
TF1 *f3 = new TF1("f3",Form("%f",yc_low[nx]),0,10);
f3->SetLineColor(4);
TF1 *f4 = new TF1("f4",Form("%f",yc_high[nx]),0,10);
f4->SetLineColor(4);
if(xc1_s<xc_high[nx]&&xc1_s>xc_low[nx]){
for (Int_t ny=0;ny<biny;ny++){
if(yc1_s<yc_high[ny]&&yc1_s>yc_low[ny]){
histXC1YC1[biny*nx+ny]->Fill(xc1_s,yc1_s); //fill w/ data
}
}
}
}

TCanvas *c0 = new TCanvas("c0","c0",970,600);
for(Int_t k=0; k<binx*biny; k++){
}
h->Draw("NOSTACKCOLZ");
f1->Draw("lsame"); //doesnt work
f2->Draw("lsame"); //doesnt work
f3->Draw("lsame"); //doesnt work
f3->Draw("lsame"); //doesnt work
c0->Print("areaz.png");
``````

_ROOT Version:5.34.34
Platform: Not Provided
Compiler: Not Provided

Try:

``````TGraph *g_low = new TGraph(binx, xc_low, yc_low);
// g_low->SetPoint(binx, xc_low[0], yc_low[0]); // "close" the graph
g_low->SetLineColor(kGreen);
TGraph *g_high = new TGraph(binx, xc_high, yc_high);
// g_high->SetPoint(binx, xc_high[0], yc_high[0]); // "close" the graph
g_high->SetLineColor(kRed);
// ...
h->Draw("NOSTACKCOLZ");
g_low->Draw("L");
g_high->Draw("L");
``````

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