Hello, Below is a ROOT code which reads a contents of the histogram from the ASCII file, and draws it. I want to put a title above the histogram and two labels for each axis. But they don't show up on the canvas when I draw a histogram with Be_hist -> Draw. I get the title and two labels for the axes but not a histogram when I comment Be_hist -> Draw. I would like to have those labels for the axes in the center not at the end of the axis. May be there is an easy way to do it, but I could not find it. Also how do I put ticks on all four axes of the histogram? I have been using ROOT v2.09 on Solaris 2.5. Any help is very appreciated. Michal Lijowski ------------------------------------------------------------------------ Michal Lijowski Washington University Research Associate St. Louis, MO 63130-4899, USA Department of Physics phone: 314-935-6285 Campus Box 1105 email: lijowski@cosray2.wustl.edu ------------------------------------------------------------------------ void Make_Be_hist() { Int_t NBINS = 173; Int_t NLINES = 34; char infile[80], indir[132] = "/export/home/lijowski/ace/cris/flight/data/"; char sline[80]; Int_t ii, jj; gROOT -> Reset(); TCanvas *c1 = new TCanvas("c1","Be Isotopes", 900, 700); // c1 -> Range(0, 0, 10, 10); c1 -> SetGrid(1,1); title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "Be Isotopes"); title -> SetFillColor(16); title -> Draw(); // Create Be histogram Float_t xmin = 4.22; Float_t xmax = xmin + (float) NBINS * 0.05; Be_hist = new TH1F("Be_hist", "Be Isotopes", NBINS, xmin, xmax); // Be_hist -> SetXTitle("Calculated Mass"); // Be_hist -> SetYTitle("No. of Events per 0.05 Mass Units"); TText *xlabel = new TText(); xlabel -> SetTextFont(1); xlabel -> SetTextColor(1); xlabel -> SetTextSize(0.03); xlabel -> SetTextAlign(12); xlabel -> SetTextAngle(0); xlabel -> DrawText(0.5, 0.1, "Calculated Mass"); TText *ylabel = new TText(); ylabel -> SetTextFont(1); ylabel -> SetTextColor(1); ylabel -> SetTextSize(0.03); ylabel -> SetTextAlign(12); ylabel -> SetTextAngle(90); ylabel -> DrawText(0.1, 0.3, "No. of Events per 0.05 Mass Unit"); // open file with Be sprintf(infile, "%sbe_hist.dat", indir); fprintf(stderr, " %s\n", infile); FILE *infp1 = fopen(infile, "r"); if (infp1 == NULL) { fprintf(stderr,"Fit_Be_hist: can't open '%s'\n", infile); exit(1); } for (ii = 0; ii < 5; ii++) fgets(sline, 80, infp1); // Now read data; each line but the last line has only 3 entries Float_t bin = 0; fprintf(stderr, " Be \n"); for (ii = 0; ii < NLINES; ii++) { fgets(sline, 80, infp1); for (jj = 0; jj < 5; jj++) { Float_t aa = (float) atoi(sline + jj * 10); Be_hist -> AddBinContent(bin, aa); bin++; } } // read the last line with 3 entries fgets(sline, 80, infp1); for (jj = 0; jj < 3; jj++) { aa = (float) atoi(sline + jj * 10); Be_hist -> AddBinContent(bin, aa); bin++; } fclose(infp1); Be_hist -> Draw(); }
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:34 MET