Hi all,
I’m trying to add a grid to all the histograms included in a root file but up to now I have been unsuccessful, here is the code and the root file
[code]void DrawGrid(){
TPad *grid = new TPad(“grid”,"",0,0,1,1);
grid->Draw();
grid->cd();
grid->SetGrid();
grid->SetFillStyle(4000);
TH2 *hgrid = new TH2F(“hgrid”, “”, 64, .5, 64.5, 48, -.5, 47.5);
hgrid->Draw();
hgrid->GetXaxis()->SetNdivisions(64);
hgrid->GetYaxis()->SetNdivisions(48);
hgrid->GetYaxis()->SetLabelOffset(999.);
hgrid->GetXaxis()->SetLabelOffset(999.);
delete grid;
delete hgrid;
}
void PlotZeroNoiseHisto(const char* filein=“Tucs.HIST.root”){
TFile* fin = new TFile(filein) ;
fin->cd(“Noise”);
TDirectory *dir = gDirectory;
if (!fin->IsOpen()){
printf("<E> Cannot open input file %s\n",filein);
exit(1);
}
TList* list = dir->GetListOfKeys();
if (!list){
printf("<E> No keys found in file\n");
exit(1);
}
TIter nextkey(dir->GetListOfKeys());
TKey* key;
TCanvas c1;
TPad *grid = new TPad(“grid”,"",0,0,1,1);
TH2 *hgrid = new TH2F(“hgrid”, “”, 64, .5, 64.5, 48, -.5, 47.5);
gStyle->SetOptStat(0);
c1.Print(“zero_noise_plots.ps[”);
while (key = (TKey*)nextkey()){
key = (TKey*)nextkey();
TH2 h2 = (TH2)key->ReadObj();
cout << h2->GetName() << endl;
h2->GetXaxis()->SetNdivisions(32);
h2->GetXaxis()->SetLabelSize(0.03);
h2->GetYaxis()->SetNdivisions(24);
h2->GetYaxis()->SetLabelSize(0.03);
h2->Draw(“col”);
DrawGrid();
c1.Print(“zero_noise_plots.ps”);
}
c1.Print(“zero_noise_plots.ps]”);
}[/code]
The two problems I get are that either the grid is not drawn or the histogram is not drawn.
Another thing I whish to achieve is the labels on the x axis, they should start with 1 and not with 2.
Tucs.HIST.root (12.6 KB)