To fill a histogram by reading text file

You did not type the cp commands correctly … you missed the point at the end … the two cp command did not work. … you got error messages … type exactly what I send you … do not forget the “.” !

Side Note: I would be more efficient to copy paste the text you type instead of posting screen dumps … they are hard to read…

Thank u very much Couet !! Could u explain me what’s the meaning with this “.” in the cp command ?

I think you need to learn a bit about the unix/linux commands. What you are asking here is very basic. You will encounter many problems if you do not master at least the minimum … and that’s really the minimum :slight_smile:

Okay, i will learn it from now on !

Thank you very much :wink:

Try these tutorials:

http://www.ee.surrey.ac.uk/Teaching/Unix/

The “.” refers to the present working directory.

Hello ksmith,

Okay i will check it right now !

Thank you very much :wink:

Hello,

i have a problem with root version 6_08_06 using the instruction " return 0 " , but it worked in the version 5.34.34 !

I wonder if there is another instruction which has the same rule of “return 0” in root version 6.08.06 ?

Thanks in advance,

It’s not clear what you are asking about. You should open a new thread with a little piece of example code.

return 0; should work in both versions.

Here is the code, i want to cancel the process once i press “0”

Does the function containing this code has a return value parameter or is it void ?
Your screen shot does not show the function signature…

It’s void

If your function returns “void” (i.e. NOTHING), you should have “return;”

Thank u all for helping !! @Wile_E_Coyote @couet @ksmith

I have a text file . I made a histogram with range from 200 to 2000 with bin 2 .
I want to read the text file and using fill () command want to sort the data into the histogram .
How do I do that ?

Thanks
Saradindu

Look at the macro expo.C posted earlier in this thread.

Hi,

I have a txt file in which the data are separated by commas. I need to make a histogram with the X axis ranging from 0 to 205 with 205 bins :

{
   TH1F *h = new TH1F("h", "example histogram",205.,0..,205.);
   ifstream inp; double x;
   inp.open("try.txt");
   for (int i=1; i<=205; i++) {
      inp >> x;
      h->SetBinContent(i,x);
   }
   h->Draw();
}

But unfortunately, this doesn't work and I get an empty histogram. Can someone help me with this
[try.txt|attachment](upload://8XfgRDDcQREBjWjc37OTr7OKfn9.txt) (589 Bytes)
?


try.txt (589 Bytes)

char c; inp >> x >> c;

I tried it and it doesnt work:

{
TH1F *h = new TH1F(“h”, “example histogram”,205.,0.,205.);
ifstream inp; double x;

inp.open(“try.txt”);
for (int i=1; i<=205; i++) {
char c;
inp >> x >> c;
h->SetBinContent(i,c);

}
h->Draw();
}
Capture

h->SetBinContent(i, x);