Paleo
October 2, 2018, 12:53pm
1
Hi,
I project a TTree
onto a histogram, and apply cuts to them. If I use a specific cut, the displayed histogram axes limits change too, which is not what I want. I would only like the data points that are displayed to change based on the cuts I apply.
I’ve tried to use SetLimits()
and SetRange()
but that doesn’t force the axes to remain independent of the cuts.
Any help?
couet
October 2, 2018, 2:32pm
2
Do you have a small reproducer ? You create the histogram before projecting ? can you show the commands you are using ?
Paleo
October 2, 2018, 4:09pm
3
Hi,
These are .root
files that are required to run smallReproducible.C
You may notice that the longitude
axis is not starting from -180
ish to 180
ish. This causes the map of the Earth to be mirrored.
The archerTree
object and its data points are included as it may have a bearing on the graph that is plotted.
ArcherTree.root (170.2 KB)
ElevationB.root (447.6 KB)
smallReproducible.C (1.7 KB)
couet
October 3, 2018, 8:25am
4
Thanks for you example.
First replace SURF5 by SURF3 to avoid the warnings.
In your code I see:
archerTree->Project( "h", "(-1*BathDepth):(longit):latit" );
And before you have:
//Cuts that I would like to use but produce desired axes limits
TCut cutDepth2030 = "(CaCO3 != -999 && BathDepth > 2000 && BathDepth < 3000)*(abs(CaCO3))";
TCut cutInd = "longit >= 30 && longit <120 && latit >= -55 && latit < 15";
You are not using the cuts in the project command. Why ?
Paleo
October 3, 2018, 1:43pm
5
I think there is a line of code that I have commented out which uses that. I just commented that out initially to show the difference between using a cut and without it.
couet
October 3, 2018, 2:20pm
6
May be the following will help:
void smallReproducible()
{
TFile* rootFile = TFile::Open("ElevationB.root");
TFile* treeFile = TFile::Open("ArcherTree.root");
TGraph2D* BSeaLevel = new TGraph2D(360*720); //2D array with N rows and M cols
rootFile->GetObject("Bathymetry_overlay", BSeaLevel);
TTree* archerTree = new TTree("archerTree", "archerTree"); // Tree with branches such as "CaCO3" and "BathDepth", and are used in TCut
treeFile->GetObject("ARCHERTREE", archerTree);
//Cuts that I would like to use but produce desired axes limits
TCut cutDepth2030 = "(CaCO3 != -999 && BathDepth > 2000 && BathDepth < 3000)*(abs(CaCO3))";
TCut cutInd = "longit >= 30 && longit <120 && latit >= -55 && latit < 15";
TCanvas* c2 = new TCanvas( "c2", "Elevation Overlay", 1500, 500 );
c2->Divide(3,1);
TH3F* h = new TH3F( "h", "BathDepth vs longitude vs latitude", 100, 0., -1., 100, 0., -1., 100, 0., -1. );
archerTree->Project( "h", "(-1*BathDepth):longit:latit", cutDepth2030 && cutInd );
c2->cd(1); h->Draw("BOX");
gPad->Update();
BSeaLevel->SetMaximum(h->GetZaxis()->GetXmax());
BSeaLevel->SetMinimum(h->GetZaxis()->GetXmin());
BSeaLevel->GetXaxis()->SetRangeUser(h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax());
BSeaLevel->GetYaxis()->SetRangeUser(h->GetYaxis()->GetXmin(), h->GetYaxis()->GetXmax());
c2->cd(2); BSeaLevel->Draw("SURF3");
c2->cd(3); BSeaLevel->Draw("SURF3"); h->Draw("BOX SAME");
}
Paleo
October 3, 2018, 2:53pm
7
Does this fix make the TGraph2D
change size according to the cuts made on the TTree
?
couet
October 4, 2018, 7:49am
8
Yes because the TGraph2D limits are defined from the histogram limits (see the code).
@couet In your example, you twice execute “new” and then “GetObject”. It seems to me that they result in memory leaks.
couet
October 4, 2018, 8:14am
10
Wile_E_Coyote:
In your example
To be honest I did not look at the beginning of the macro… I concentrated on the graphics part. I will check .
couet
October 4, 2018, 8:19am
11
void smallReproducible()
{
TFile* rootFile = TFile::Open("ElevationB.root");
TFile* treeFile = TFile::Open("ArcherTree.root");
TGraph2D *BSeaLevel = (TGraph2D*)rootFile->Get("Bathymetry_overlay");
TTree *archerTree = (TTree*)treeFile->Get("ARCHERTREE");
//Cuts that I would like to use but produce desired axes limits
TCut cutDepth2030 = "(CaCO3 != -999 && BathDepth > 2000 && BathDepth < 3000)*(abs(CaCO3))";
TCut cutInd = "longit >= 30 && longit <120 && latit >= -55 && latit < 15";
TCanvas* c2 = new TCanvas( "c2", "Elevation Overlay", 1500, 500 );
c2->Divide(3,1);
TH3F* h = new TH3F( "h", "BathDepth vs longitude vs latitude", 100, 0., -1., 100, 0., -1., 100, 0., -1. );
archerTree->Project( "h", "(-1*BathDepth):longit:latit", cutDepth2030 && cutInd );
c2->cd(1); h->Draw("BOX");
gPad->Update();
BSeaLevel->SetMaximum(h->GetZaxis()->GetXmax());
BSeaLevel->SetMinimum(h->GetZaxis()->GetXmin());
BSeaLevel->GetXaxis()->SetRangeUser(h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax());
BSeaLevel->GetYaxis()->SetRangeUser(h->GetYaxis()->GetXmin(), h->GetYaxis()->GetXmax());
c2->cd(2); BSeaLevel->Draw("SURF3");
c2->cd(3); BSeaLevel->Draw("SURF3"); h->Draw("BOX SAME");
}
Using “Get” should be prohibited by law.
TGraph2D *BSeaLevel; rootFile->GetObject("Bathymetry_overlay", BSeaLevel);
TTree *archerTree; treeFile->GetObject("ARCHERTREE", archerTree);
1 Like
system
Closed
October 18, 2018, 8:22am
13
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.