Fill histogram by file

HI, I must fill histogram by txt file. I wrot the macro, but I get this error


How to fix?
thanks
histo.c (808 Bytes) dati.txt (345 Bytes)


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.18/04
Platform: Windows 10
Compiler: Not Provided


Add #include <fstream> and change inp->open(datain); to inp.open(datain); and inp->close(); to inp.close();

Hi @bellenot, thank you but I still get error

histo.c (826 Bytes)

OK, so this doesn’t work with ROOT v6.18.04, but works with v6.20.00. Note that the version 6.20.00 might not work on your system if the version of Visual Studio (or the SDK) is different than the one used to build ROOT. But you can try nevertheless. Otherwise you can build from source

thank you @bellenot isn’t there a way for root 6.18?

Well, maybe, but there were many changes between 6.18 and 6.20…
Why not trying 6.20?

Hi @bellenot, I installed Root 6.20 and the macro works, but it doesn’t look like working fine. Data should be a Gaussian-like function distribution…I should get this graph

but i get the one in attachment! t’s different for shape and number of counts on y axis… o_O

histo.c (827 Bytes)

dati.txt (345 Bytes)
histo.pdf (13.5 KB)

Well, the histogram matches your data…

@bellenot no…because in the range [25,26] I should have 2 data, in the range [26;27] 2 data, i range [27;28] 6 data etc…

h->Fill(x); instead of h->SetBinContent(i,x);

1 Like

Thank you @Wile_E_Coyote it solved!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.