I am trying to draw two histograms from a .dat file. The file contains 3 rows, the first being the “channel” number and the two remaining the bin contents. The file is attached.
When trying to plot the two histograms I get some entries, but not all of them. Although it seems that the data are correctly imported, not all of them are drawn, like the following image illustrates.
My code is the following
[code] #include “Riostream.h”
void telescopeThickness(){
gROOT->SetStyle("Plain");
gStyle->SetOptStat(0000);
gStyle->SetOptFit(1111);
gStyle->SetOptTitle(0);
TPaveText *t = new TPaveText(0.005, 0.995, 0.85, 0.905, "brNDC");//left-up
t->AddText("#delta E detector thickness measurement using ^{244}Cm source");
t->SetBorderSize(1);
t->SetFillColor(gStyle->GetTitleFillColor());
TCanvas *c = new TCanvas("c", "c");
c->SetFillColor(5);
c->SetFrameFillColor(10);
TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
dir.ReplaceAll("telescopeThickness.C","");
dir.ReplaceAll("/./","/");
ifstream in;
in.open(Form("%stelescopeThickness.dat",dir.Data()));
Float_t x,y,z;
Int_t nlines = 0;
Int_t channels=1024;
TH1F *h1 = new TH1F("h1","Total",channels,1,channels);
TH1F *h2 = new TH1F("h2","#alpha background",channels,1,channels);
while (1) {
in >> x >> y >> z;
if (!in.good()) break;
if (nlines == 494) printf("x=%8f, y=%8f, z=%8f\n",x,y,z);
h1->Fill(x,y);
h2->Fill(x,z);
nlines++;
}
printf("Found %d points\n",nlines);
in.close();
h1->SetLineColor(8);
h1->SetFillColor(8);
h1->SetLineWidth(4);
h1->Draw();
h1->GetXaxis()->SetTitle("Energy[keV]");
h1->GetYaxis()->SetTitle("Events");
h1->GetYaxis()->SetRangeUser(1,2.2);
h2->SetLineColor(kBlue);
h2->SetFillColor(kBlue);
h2->SetFillStyle(3395);
h2->SetLineWidth(2);
h2->Draw("same");
TLegend *leg = c->BuildLegend();
//c->SetLogy();
t->Draw();
//c->SaveAs("alphaBG.pdf");
}[/code]
Any idea on what might be wrong? Thank’s a lot in advance!
telescopeThickness.dat (14 KB)