Filling a Histogram from a text file

Hello,

I currently have a text file (attached), from which I need to draw data and fit in a histogram. The fitting part I know how to do, but I am having trouble extracting the data from the .txt and drawing it in a histogram. I’ve got two versions of my code, neither of which really work.

This one draws only the first event:

[quote]
TTree NoiseTree = new TTree(“NoiseTree”, “NoiseTree”);
NoiseTree->ReadFile("/11_noPreamble.txt", “mV”);
TH1F
NoiseHist = new TH1F(“Signal And Noise”, “Signal And Noise”, 200, -160, 40);
NoiseTree->Draw(“mV>>NoiseHist”);[/quote]

While this one draws the first event, and a few value=0 events it gets from I don’t know where:

[quote]TTree NoiseTree = new TTree(“NoiseTree”, “NoiseTree”);
NoiseTree->ReadFile("/11_noPreamble.txt", “mV”);
TH1F
NoiseHist = new TH1F(“Signal And Noise”, “Signal And Noise”, 200, -160, 40);
int entries = NoiseTree.GetEntry();
for(int i = 0; i < entries; i++) {
NoiseHist->Fill(NoiseTree.GetEntry(i));
}
NoiseHist->Draw();[/quote]

The problem is that the file has 20,000 events, and thus the histogram should be quite a bit bigger than one event. Does anyone know how to get the code to draw every event?
11_noPreamble.txt (117 KB)

Execute: sed -i -e 's/[\r\t]/\n/g' 11_noPreamble.txt

Did that. Got a whole bunch of “____ not defined in current scope”. I don’t think it will work, not that I know what it does.

If possible, I’d prefer solutions involving code. I have a lot of files to perform this procedure on, having to manually enter commands on the command line would make things difficult.

The command that I gave you is NOT a ROOT command. You need to execute it directly in your shell prompt (then enter ROOT again and execute your own macro).

That seems to have worked. Thank you very much. Would you mind explaining to me what that command did?

For instance you can google “sed linux command tutorial”… you will get many details
or just type “man sed” at the linux prompt…