Re: ascii output
Rene Brun (Rene.Brun@cern.ch)
Thu, 10 Sep 1998 18:40:53 +0200
Jean-Pascal Laedermann wrote:
>
> Dear roottalkers !
>
> I need to output an ascii file from a histogram.
>
> I've written this little macro m60co2a4_geap.C :
>
> {
> gROOT->Reset();
>
> TFile f("m60co2a4_geap.root"); /* root file obtained
> by h2root from hbook*/
>
> FILE *f1;
> int i, nc = 4096; /*
> known numbers and limits of channels */
> float hsup = 3000;
>
> f1 = fopen ("m60co2a4_geap.tsv", "w"); /* tab separated values */
> if (!f1) puts ("? output file");
> else {
> for (i=1; i<=nc; i++) fprintf (f1, "%f\t%f\n", (i-.5)*hsup/nc,
> h21->GetBinContent(i));
> fclose (f1);
> }
>
> }
>
> h21 is the 4096 channels histogram to output, I supposed that the
> channels 0 and 4097 are for under and overflows (isn't it ?).
>
> The first time I run this macro I get
>
> fprintf parameter mismatch param[0] E C
> FILE:/home/jpl/geant/geap/current/result/spectra/m60co2a4_geap_calc.C
> LINE:13
>
> The second time
>
> 4096 times :
>
> Error: fprintf parameter mismatch param[0] E C
> FILE:/home/jpl/geant/geap/current/result/spectra/m60co2a4_geap_calc.C
> LINE:13
>
> And the third, the expected file, but after a long time.
>
> Is it a simpler way to do this ? (I use Linux 2.0.33 on a pentium 100)
>
The problem is simple. You have a parameter mismatch in your
fprintf statement.
TH1::GetBinContent returns a double, not a float.
So replace yout format %f by %g or store the result of
TH1::GetBinContent into a float.
Rene Brun