ROOT Version (e.g. 6.12/02):
Platform, compiler (e.g. CentOS 7.3, gcc6.2):
Hello everyone, i am currently working on a program that requires to draw bi-dimensional histograms (TH2F) from E and E+DeltaE TH1F. I have written the code below, and unfortunately im getting some issues depending on slight changes…
I am a ROOT beginner, i start 1 week ago so please forgive my ignorance.
for (int i = 1 ; i<= n ; i++)
{
stringstream ss ;
double e = lowestE+ (i-1)*dE ;
ss << e ;
string num = ss.str() ;
string opename = nameg+num+unit+extension ;
const char* namefile = opename.c_str() ;
TFile *File = new TFile(namefile) ;
TTree *tree = (TTree *)File->Get(nametree) ;
tree->Draw(bidimaxes, "", "goff") ;
TH2F *bidim1 = tree ->GetHistogram() ;
//tree->Draw(bidimaxes,"","") ;
bidim1->Draw() ;
TFile out(namefileout, "update") ;
string namebidim1 = nameg+num+unit+bidimhisto ;
const char* namebidim = namebidim1.c_str() ;
bidimlist.push_back(namebidim1) ;
bidim1->SetName(namebidim) ;
bidim1->Write(namebidim) ;
out.Close();
}
the TH2F histogram drawn is … squared.
What i was expecting to have was more (i will post it in the next message because i cant actually) :
(obtained when i modified my cod this way )
for (int i = 1 ; i<= n ; i++)
{
stringstream ss ;
double e = lowestE+ (i-1)*dE ;
ss << e ;
string num = ss.str() ;
string opename = nameg+num+unit+extension ;
const char* namefile = opename.c_str() ;
TFile *File = new TFile(namefile) ;
TTree *tree = (TTree *)File->Get(nametree) ;
tree->Draw(bidimaxes, "", "");
TH2F *bidim1 = tree ->GetHistogram() ;
//tree->Draw(bidimaxes,"","") ;
// bidim1->Draw() ;
TFile out(namefileout, "update") ;
string namebidim1 = nameg+num+unit+bidimhisto ;
const char* namebidim = namebidim1.c_str() ;
bidimlist.push_back(namebidim1) ;
bidim1->SetName(namebidim) ;
bidim1->Write(namebidim) ;
out.Close();
}
just mentioning that if i remove // before bidim1->Draw() , i obtain an empty histogram…
My problem was coming from the binning. When using the draw method, it produces a TGraph with automatic binning, so when i ask to save it as a TH2F it was rebin and looks like above. When i finally ask the draw method to put everything directly into a TH2F with a correct binning, everything get back to normal !
When you draw a 2D distribution in a 2D histogram with “goff” and draw the histogram, afterwards, the “scatter plot” you get is produced as explained here. That’s why you see these “boxes” … That’s a bit misleading and you better use the COL of BOX option which are less confusing, or plot a real scatter plot like the 2nd you showed.